Data Transfer Using QueryString To Other Asp.Net Pages

This posts explains how to Data Transfer Using QueryString To Other Asp.Net Pages. Several time while developing asp .NET applications we need to transfer data from one page to another, we can achieve this by several methods , some of them are

1. Using QueryStrings

2. Using Cookies

3. Using Session Variables

4. Using Cross Page Posting

5 . Using Server.Transfer


1 . QueryStrings
Suppose we have a textbox txtData and we want it's value on other page
than in code behind we would write in click event of btnGo

private void btnGO_Click(object sender, System.EventArgs e)
{
Response.Redirect("Default2.aspx?Value=" +
txtData.Text);
}

To retrieve this value on second page
private void Page_Load(object sender, System.EventArgs e)
{
txtData.Text = Request.QueryString["Value"];
}

If we have passed more than one values in querystring we can either retrieve them
by variable name or by index
private void Page_Load(object sender,System.EventArgs e)
{
txtData.Text = Request.QueryString[0];
}

QueryString can't be used for sending long data because it has a max lenght limit

Data being transferred is visible in url of browser

To use spaces and & in query string we need to replace space by %20 and & by %26
private void btnGO_Click(object sender, System.EventArgs e)
{
Response.Redirect("Default2.aspx?Value=" +
txtData.Text.Replace(" ","%20");
}

Or we can use Server.UrlEncode method

private void btno_Click(object sender, System.EventArgs e)
{
Response.Redirect("Default2.Aspx?" +
"Name=" + Server.UrlEncode(txtData.Text));
}


Continue



Related Posts:
1. Data Transfer Using Cookies Session Variables Cross page posting and QueryStrings in ASP.NET

2. Cross page posting, Submit Form and Server.Transfer methods in ASP .NET for data transfer

3. LinkButton in GridView and QueryString Parameters to pass/transfer variable and data-ASP.NET Articles

If you like this post than join us or share

4 comments:

Anonymous said...

Nice article


amiT jaiN said...
This comment has been removed by the author.

Anonymous said...

the panel which is in left side it comes above the letter. Plz decrease the width.
thank u


Anonymous said...

The social sharing buttons on the left are in the way.


Find More Articles