Query String in ASP.Net

Query String in ASP.Net

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

For send information to other page Response.Redirect() method used and for retrieve information from url use Request.QueryString() method used.

In Query String method we can sent value to only desired page, and value will be temporarily. So Query string increase the overall performance of web application.

Syntax of Query String

Send information to other page


Retrieve information from other page


Query String Example in ASP.Net

Design asp.net web form with a button control along with a textbox control. We will pass textbox value to nextpage.aspx using query string method and retrieve information from url in nextpage and display it in label control.

Query String in ASP.Net
Query String in ASP.Net

C# code for Query String Example

Write below code on SEND button click events on first page for pass information to other page.

protected void btnsend_Click(object sender, EventArgs e)
Response.Redirect(“NextPage.aspx?name=” + txtname.Text);

Write below code on Retrieve button for retrieve information from url and display it in label on Nextpage.aspx.

protected void btnretrieve_Click(object sender, EventArgs e)
Label1.Text = “Welcome ” + Request.QueryString[“name”].ToString();

Pass multiple values using Query String in ASP.Net

In above example we sent single information using query string. If we want to send multiple values in url using query string method, check below example.

Syntax to pass multiple values


Query String Example

Query String in ASP.Net
Query String in ASP.Net

C# code for Query String example

Querystrings.aspx page

NextPage.aspx page

Leave a Reply

Your email address will not be published. Required fields are marked *