Saturday, December 29, 2012

How to read URL query string in ASP.NET


In some occasions you might need to pass data from one page to another. One method we can use is pass data through the URL.

Let's say you want to redirect from page1.aspx to page2.aspx with some data on page1.aspx button click event.

Add below code to page1.aspx button click event.

Response.Redirect("Page2.aspx?Name=Chamara");

Here we are passing a Name parameter in URL query string. From Page2.aspx page load event we can use below code to read the query string parameter.

string name= Request.QueryString["Name"].ToString();
Response.Write(name);

Output:
Chamara

No comments:
Write comments
Recommended Posts × +