Famil Jones

A .NET Blog

<January 2009>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567


Navigation

Links

Subscriptions



Thursday, April 08, 2004 - Posts

Pass Variables Between ASP.NET Pages

You can always pass variables between ASP.NET pages as part of a query string in the URL. If your form is not running at server you can also use the Request object to retrieve the values of the form elements (especially hidden input elements for this purpose). However, if you have a form with runat=server, and you don't want to expose the variables to the user then your choices are limited. Here is a way to pass variables between ASP.NET pages:

1. In your SendingPage.aspx add an item to the context.
  Dim variableToPass as String = "Passed Value"
  Context.Items.Add("variableToPass", variableToPass)

2. In your SendingPage.aspx call Server.Transfer to transfer to your ReceivingPage.aspx.
  Server.Transfer("ReceivingPage.aspx", True)

3. In your ReceivingPage.aspx retrieve the variable from the context.
  Dim receivedValue As String
  receivedValue = Context.Items("variableToPass")

Note that the page URL in the address bar of the browser window will stay as SendingPage.aspx even though you are now in ReceivingPage.aspx. You can get more information on Server.Transfer vs. Response.Redirect at http://www.developer.com/net/asp/article.php/3299641.

If you are interested in passing server control values between ASP.NET pages please refer to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconPassingServerControlValuesBetweenPages.asp.

Famil Jones,
Karamasoft

posted Thursday, April 08, 2004 7:13 AM by Famil Jones with 3 Comments




Powered by Dot Net Junkies, by Telligent Systems