Passing in a variable using a query string

G

Guest

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
 
B

Bryan Lynn

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top