Connecting Tech Pros Worldwide Help | Site Map

Another simple question - passing variables

Brad
Guest
 
Posts: n/a
#1: Nov 19 '05
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
Elton Wang
Guest
 
Posts: n/a
#2: Nov 19 '05

re: Another simple question - passing variables


Hi Brad,

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

HTH

Elton Wang
elton_wang@hotmail.com

[color=blue]
>-----Original Message-----
>I have another hopefully simple question. I am so used[/color]
to writing VB .Net[color=blue]
>windows apps that there are some things in ASP .Net that[/color]
just does not easily[color=blue]
>cross over. I know how to pass variables to another[/color]
form, but how would I do[color=blue]
>this from one page to another? I am not finding a simple[/color]
solution.[color=blue]
>
>Thanks for the help
>.
>[/color]
Brad
Guest
 
Posts: n/a
#3: Nov 19 '05

re: Another simple question - passing variables


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")


Steve C. Orr [MVP, MCSD]
Guest
 
Posts: n/a
#4: Nov 19 '05

re: Another simple question - passing variables


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/is...e/default.aspx

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

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

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


"Brad" <Brad@discussions.microsoft.com> wrote in message
news:EA176277-B6CD-4A09-B998-787FB516F431@microsoft.com...[color=blue]
>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[/color]


Closed Thread