ASP.NET 1.1
There are three widely used methods of passing values from one page to another in ASP.NET 1.1.
1. Using Query String
We usually pass value through query string of the page and then this value is pulled from Request object in another page.
FirstForm.aspx.cs
Response.Redirect("SecondForm.aspx?Parameter=" + TextBox1.Text);
SecondForm.aspx.cs
TextBox1.Text = Request. QueryString["Parameter"].ToString();
Very straightforward! Only problem with this method is that we need to pass value under the constraint of maximum characters (read 2083 characters) allowed in URL. If you pass string larger than that, your application will going to crash. So it is reliable only when you are passing integer kind of value or if you are sure about size of value will not exceed maximum URL length. If parameter is larger than maximum URL length or if you are not sure about its length, then prefer not to use query string to pass value.
Another problem is that user can actually see the passing parameters and its value in address bar which further require to validate each parameter after pulling it from Request object.
You also have to take care of any special characters in the value while passing it through query string. So you must encode the value before passing it to next page. And likewise, you decide that passed value after pulling from Request object. So our code snippet of pulling passed value will be something like this:
FirstForm.aspx.cs
Response.Redirect("SecondForm.aspx?Parameter=" + Server.UrlEncode(TextBox1.Text));
SecondForm.aspx.cs
TextBox1.Text = Server.UrlDecode(Request.QueryString["Parameter"].ToString());
This approach is very handy if you have to pass some integer like values, for example like employee id, order id etc.
2. Using Context Object
Passing value through context object is another widely used method.
FirstForm.aspx.cs
TextBox1.Text = this.Context.Items["Parameter"].ToString();
SecondForm.aspx.cs
this.Context.Items["Parameter"] = TextBox1.Text;
Server.Transfer("SecondForm.aspx", true);
Note that we are navigating to another page using Server.Transfer instead of Response.Redirect.
One of the major benefits of using Context object for passing values is that passed value will not shown to user at address bar while navigating to next page. This means developer needs not to worry about validating parameter value after pulling from Context object. There is no limitation of size of parameter passed using Context object as it method does not depend upon URL of page.
Some developers also use Session object to pass values which I never prefer at all. In that method, value is store in Session object and then later pulled out from Session object in Second page.
3. Posting form to another page instead of PostBack
Third method of passing value by posting page to another form, like what we were doing in ASP age. Here is the example of that:
FirstForm.aspx.cs
private void Page_Load(object sender, System.EventArgs e)
{
buttonPassValue.Attributes.Add("onclick", "return PostPage();");
}
And we create a javascript function to post the form.
FirstForm.aspx
<script language=javascript>
function PostPage()
{
document.Form1.action = "SecondForm.aspx";
document.Form1.method = "POST";
document.Form1.submit();
}
</script>
SecondForm.aspx.cs
TextBox1.Text = Request.Form["TextBox1"].ToString();
Here we are posting the form to another page instead of itself. And pulling value of control of previous page through Request object.
NOTE: You might get error “The viewstate is invalid for this page and might be corrupted.†in second page using this method. Workaround to handle this error is to put EnableViewStateMac=false in Page declaration of form
SecondForm.aspx
<%@ Page language="c#" Codebehind="SecondForm.aspx.cs" AutoEventWireup="false" Inherits="WebApplication17.SecondForm" EnableViewStateMac=false%>
ASP.NET 2.0
In ASP.NET 2.0, Microsoft has solved this problem by adding PostBackURL property of control for cross page post back. Implementation is a matter of setting one property of control and you are done.
FirstForm.aspx
<asp:Button id="buttonPassValue" style="Z-INDEX: 102;" runat="server" Text="Button" PostBackUrl="~/SecondForm.aspx"></asp:Button>
SecondForm.aspx.cs
TextBox1.Text = Request.Form["TextBox1"].ToString();
In above example, we are assigning PostBackUrl property of the button we can determine the page to which it will post instead of itself. In next page, we can access all controls of the previous page using Request object.
You can also use PreviousPage class to access controls of previous page instead of using classic Request object.
SecondForm.aspx.cs
TextBox textBoxTemp = (TextBox) PreviousPage.FindControl("TextBox1");
TextBox1.Text = textBoxTemp.Text;
As you have noticed, this is simple and clean implementation of passing value between pages.
Passing values between pages is another common task accomplishes in web based development. As we have discussed many of mechanisms above, I always prefer and recommend to use posting form to another page then other methods, if its web development in ASP.NET 1.1. If it’s in ASP.NET 2.0, then I prefer to use PostBackURL for its clean implementation.

[...] In my previous post, I have written about passing value between pages of same application. How about if you want to send some data from one application to another? In continuation of my previous post, let’s discuss about passing value between applications. [...]
this works fine with normal pages but i have 2 different content pages and i want values of 1 content page in other content page.
How to achieve that ?
can v use a varialbe declared in first form as a parameter?
but it doesnt recognise x in second form as it is not declared .
what should be used at parameter.
please reply
regards
vashisth
I have struggled to understand ASP.NET 2.0 querystrings that can recieve dynamic parameters at run time. At this blog, i king of got the picture but still its less detailed. It would be nice if you directed to a more detailed link about the topic.( querystrings)