471,344 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 software developers and data experts.

Passing in a variable using a query string

I haven't done any web work for over a year and for the life of me I cannot
remember how to use a query string in a URL. I want the link to be
page.aspx?ID=1 then pass 1 into a query like this

select * from table where id = "query string value"

I know it's simple, I just haven't done it for a long time. Can somebody
please help me out? Thanks
Jul 21 '05 #1
2 1879
The System.Web.HttpContext.Current.Request.QueryString property will
return a NameValueCollection containing all of the variables in the
query string.

So in csharp, this:
System.Web.HttpContext.Current.Request.QueryString["ID"]

....will return the value of ID variable in the query string.

Jul 21 '05 #2
Hi Andy,

Its very simple...

If you want to pass data (value) from pageA to pageB on click of a button,
then on the click event of the button in pageA..

Response.Redirect("FULL_URL_OF_THE_PAGE?Value1=" + Value_you_want_to_send +
"&Value2=" + Value_you_want_to_send);

And in pageB page load event (in the if(!postback)) capture the query string
value like this...

string query = "select * from Products where ProductID='" +
Request.QueryString [ "Value1" ] + "'";

As Bryan explained, A NameValueCollection containing the collection of query
string variables will be sent to the next page.

NOTE: In this example i have given how to capture for 2 values in Query
string.

Need any help, do post a msg back..
Happy Coding.

"Andy" wrote:
I haven't done any web work for over a year and for the life of me I cannot
remember how to use a query string in a URL. I want the link to be
page.aspx?ID=1 then pass 1 into a query like this

select * from table where id = "query string value"

I know it's simple, I just haven't done it for a long time. Can somebody
please help me out? Thanks

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Paul | last post: by
3 posts views Thread by domeceo | last post: by
6 posts views Thread by Scott Zabolotzky | last post: by
2 posts views Thread by Keith | last post: by
1 post views Thread by Deecrypt | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.