Wednesday, 1 January 2014

What is Query String in Asp.Net

What is Query String in Asp.Net

Query String in Asp.Net: Query String is special kind of object which resides at client side. It is used to transfer non-sensitive (because data sent by query string is visible in url ) data from one page to another page with same domain or with another domain. We can send maximum 2048 bytes data with Query String

·         The data sent by query string is visible in url
·         It can send up to 2200 to 2300 char with query string
·         The data sent should be of string type
·         The query string in the url is separated by “?” mark

Example with Query String……………………………….

Code for How to set any textbox value with query String…………………….
protected void Button1_Click(object sender, EventArgs e)
{
txtemailid.Text = "vinay.sanger.singh@gmail.com";
Response.Redirect("Default2.aspx?emailid=" + txtemailid.Text);
}
Code for How to get textbox value to another web Page with query String…………………….
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = Request.QueryString["emailid"];
}

How to use Query String with different Key value …………………………


Code for How to set different key value with query String…………………….
protected void Button1_Click(object sender, EventArgs e)
    {
   Response.Redirect("Default2.aspx?key1="+txtname.Text+"&  key2="+txtmobileno.Text+"& key3="+txtemailid.Text+"");
    }
Code for How to get different key value to another web Page with query String…………………….
protected void Button1_Click(object sender, EventArgs e)
{
foreach (string str in Request.QueryString.AllKeys)
{
Response.Write(str+"=" );
Response.Write(Request.QueryString.Get(str) + "<br>");
}
}


Result :


0 comments:

Post a Comment