Follow in Twitter & Facebook



Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools



Wednesday, August 8, 2012

Query String in Asp.Net

In this article we will discuss about another state management technique query string in asp.net. You can also check my last article on Cross page posting in Asp.Net here.

Query String is one of the useful technique in Asp.Net to transfer values from one page to another page.

Syntax:
Response.Redirect("~/SecondPage.aspx?ID=1");

You can also pass multiple parameters like below:

Response.Redirect("~/SecondPage.aspx?ID=1&Name=SharePointDotNet");

To retrieve the values like below:

int intID=Convert.ToInt32 (Request.QueryString["ID"]);

string strName= Request.QueryString["Name"].ToString();

This is one of the simplest technique. The advantage of query string is that it’s lightweight and doesn’t exert any kind of burden on the server. But there are some limitations also.


Limitations:
- The information should be simple string and should contain legal characters.

- Information is clearly visible to the user, so it not recommended for sensitive information.

- The amount of data depends upon the brower url length capabilities which is 1kb or 2kb.

Since the URL is visible to users we can encode that like below:

Response.Redirect("~/SecondPage.aspx?ID=Server.UrlEncode(1)");

And to decode the value we have to use UrlDecode value:

int intID=Convert.ToInt32 (Server.UrlDecode((Request.QueryString["ID"])));




0 on: "Query String in Asp.Net"