Access ASP.NET Form or Control Values from One Page in Another Page

Passing submitted values from a form on one page to another page for further processing is a common need in web and intranet applications. There are many ways to meet that need, such as using QueryString or Session variables. However, another?often more convenient?technique is to use the Server.Transfer() method.

Server.Transfer() transfers control to another web form—completely on the server, without a client-side redirect. Server.Transfer requires two parameters: (1) the name of the Web Form to which you want to pass control and (2) the Boolean value that determines whether ASP.NET should preserve or discard the current form state when it executes the new form. As you probably expect, to pass form values from one Web Form to another, set the second parameter to True.

The following code transfers control from a submitted form to a destination page.

Server.Transfer("destination.aspx", True)

In the preceding code, destination.aspx is the name of the page to which control is transferred, and the Boolean value True indicates that ASP.NET should preserve the current form state in the destination page.

Now, suppose the original form contained TextBox control with an ID of TextBox1. You can now access the value of that control in destination.aspx. For example, the following line would print out the value of the TextBox control:


Note that you must set the EnableViewStateMac page property for the destination page to False for this to work.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: