By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,133 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,133 IT Pros & Developers. It's quick & easy.

Passing in a variable using a query string

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.