Query string in asp.net c# with example

Query string is a simple way to pass some information from one page to another. The information cab be easily pass to one page to another or to same page. With query string method the information passed in url of page request.

This tutorial explains –
  • What is QueryString?
  • Why do we use QueryString?
  • How to pass the values through QueryString?
  • How to retrieve the values from QueryString?

This method many browsers supports only 255 character length of url in query string. The value passed will be visible so some time it cause security issue.

Query string consist of two parts (field and value), and each of pair separated by ampersand (&).

Query strings are visible to the user, hence should not be used to send sensitive information (Like Username, Password), unless encrypted.

To retrieve the query string value, use Request object’s QueryString property

Step 1: In Form1 we can write the following code in button event

 da.Name = TextBox1.Text;
 Response.Redirect(“WebForm2.aspx?name=” +TextBox1.Text);

Step 2 : In Form2  we can retrieve the values of the first page to second page using the Url above this code can write page load event of second page

label1.Text = Request.QueryString[“name”];

Now run project and see output

SEE MORE