Monday, January 23, 2012

Querystring


QueryString can maintain limited state information. Data can be passed from one page to another with the URL but you can send limited size of data with the URL. Most browsers allow a limit of 255 characters on URL length but Some browsers and client devices have the 2083-character limit on the length of URLs..

You can use a query string to submit data back to your page or to another page through the URL. Query strings provide a simple but limited way of maintaining some state information. For example, query strings are an easy way to pass information from one page to another, such as passing a product number to another page where it will be processed.


Response.Redirect("Home.aspx?Email=" +txtEmailid.Text);
lblEmail.Text = Request.QueryString["Email"];

or

    protected void Page_Load(object sender, EventArgs e)
    {
string str = Request.QueryString["Email"];
if (str != null)
{
   Response.Write("Email is: "+str);   
}
string strSecond = Request.QueryString["Email"];
if (strSecond != null)
{
   Response.Write("Email detected");
}
    }


Advantages of Querystring:
1: No server resources are required. The query string is contained in the HTTP request for a specific URL.
2: Widespread support. Almost all browsers and client devices support using query strings to pass values.
3: Simple implementation. ASP.NET provides full support for the query-string method, including methods of reading query strings using the Param property of the HttpRequest object.

Disadvantages of Querystring:
1: Potential security risks   The information in the query string is directly visible to the user via the browser's user interface. A user can bookmark the URL or send the URL to other users, thereby passing the information in the query string along with it. If you are concerned about any sensitive data in the query string, consider using hidden fields in a form that uses POST instead of using query strings. 
2: Limited capacity. Some browsers and client devices have the 2083-character limit on the length of URLs.

No comments: