Another simple question - passing variables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have another hopefully simple question. I am so used to writing VB .Net
windows apps that there are some things in ASP .Net that just does not easily
cross over. I know how to pass variables to another form, but how would I do
this from one page to another? I am not finding a simple solution.

Thanks for the help
 
Hi Brad,

You can use ApplicationState, SessionState, ViewState, or
Cookies to share data in different pages of one
application.

HTH

Elton Wang
(e-mail address removed)
 
I did find something and it seems to be working:

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")
 
Here's a nice, simple way to pass values from one page to another:
(VB.NET code)

'Add data to the context object before transferring
Context.Items("myParameter") = x
Server.Transfer("WebForm2.aspx")

Then, in WebForm2.aspx:

'Grab data from the context property
Dim x as Integer = CType(Context.Items("myParameter"),Integer)

Of course there are a number of ways to pass values from one page to
another, such as using the querystring, cookies, session,
context, saving to a temporary table in the database between each page, etc.
You'll have to decide which technique is best for your application.
Here are several good articles on the subject to help you decide.
http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/default.aspx

http://www.aspalliance.com/kenc/passval.aspx

http://www.dotnetbips.com/displayarticle.aspx?id=79
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top