Thursday 17 August 2017

What is Query String ? Why we use Query Sting in ASP.Net?

Query String is Data Navigation technique which is used for Sending the data from one web form to another web forms.
Query String is Pair of Name/Value Collection and it is appended to the page URL.

For Example : if we have two web forms one is default1.aspx and another is default2.aspx.
User wants to send EmailID and UserName from Default1.aspx to default2.aspx then we have to append EmailId and UserName to URL like below code

Response.Redirect("Default2.aspx?UserName="+txtUsername.Text+"&EmailID="+txtEmail.text+);

Question Marks (?) indicated beginning of a Query String and it's value.
Ampersand (&) indicates another query sting variable.

In the Above example UserName is one variable in which we holds the values from txtUsername.text  and EmailID is the second variable which holds the value of EmailID.. so in the above code we use two query strings concatenate by & symbol.

There is some limitations of Query String data so that we can not send long data by query string.
Query strings are visible to the users so can not send the sensitive data by query string unless use ENCRYPTION of Url..
To read query string data we use Request object's Query string properties.


On the webform Default2.aspx load event we can read query string values like that

txtUserName=Request.QueryString["UserName"];
txtEmailId=Request.QueryString["EmailID"];

No comments:

Post a Comment

Creating First WEB API Project from scratch ?

  For creating Web API project open your Visual Studio Editor and Create New Project as shown in below figure. Now you have to select  ASP.N...