Click Here To Get Amazing Facebook Profile Covers,Status Messages

Howto use QueryString in ASP.NET for passing info between pages.

The QueryString in ASP.NET is used to pass information between pages.
Suppose you have ID of a user at one page and you want display the details of that particular user like first name last name

in second page then you can transfer ID in url of page using querystring and use it in second page to retrive information from database.

url with querystring loooks like this

http://localhost/details.aspx?ID=2

you must have encountered more complex urls using querystring.Generally querystring are used in master detail pages suppose

you have a list of users,employees in your grid or repeater control and you provide a detail hyperlink to show details of particular employee.

The information passed through querystring can last upto the life of that application but generally used for a single request.The data passed through querystring is appended in URL, so user can see it, therefore proper encryption should be in place before passing sensitive information.? is used at start of querystring and & appears between key value pairs in URL.

To implement it in ASP.net we use Request object's querystring property.

Response.Redirect("details.aspx?ID=" + ID_TEXT_BOX.Text);

this line of code can be used in button click event so that ID info in text box can be transfered to details page.

ID = Request.QueryString["ID"];

or

ID = Request.QueryString[0];

any of above line can be used in detail page to retrive info of ID transfered from first page.

As "&" has a special meaning in URL like this there are characters for which we need to encode our querystrings using Server.url Encode method.Also querystring has a limited max size.there are various other ways for
transfering info or maintain state in ASP.net like cookies,viewstate and session.

Your rating: None Average: 5 (1 vote)