Passing values to another web page

R

RipperT

College newbie here (Instructor MIA). I have instructions to pass variable
values from one web page to another like this (VS2005):

1. Declare and create the properties on the first page (source form):
Public ReadOnly Property UserName() As String
Get
Return userNameTextBox.Text
End Get
End Property
2. Call the next page by calling the Transfer method of the Server object:
Private Sub pageTwoButton_Click(...)
Server.Transfer("secondWebForm.aspx")
End Sub
3. In the Page_Load event of the second page, create an instance of the
source page and retrieve the property values from the instance:
Public originalPage As WebForm
Private userName As String
Private Sub Page_Load(...)
If Not IsPostBack() Then
originalPage = CType(Context.Handler, firstWebForm)
userName = originalPage.UserName 'Retrieve the value
userLabel.Text = userName 'Preserve for future postbacks
End If
End Sub

Question: How is 'Public originalPage As WebForm' a declaration of an
instance of the first page? I can't even find WebForm as a valid type
declaration.

Many thanx,

Rip
 
C

Cor Ligthert [MVP]

Ripper,

I never succeeded to pass to another page. Remember that a page is
stateless, therefore it does not exist anymore on your server as soon as it
is send.

Most people use the long time existing Session.Items for that.

There is as well another method, but for me the Sessions.Item did it the
best.

Cor
 
R

RipperT

Thanks for the response. Our instructions mentioned the use of
Session.Items, but did not include details on how to use it. Can you provide
an example?

Many thanks,

Ripper
 
C

Cor Ligthert [MVP]

Ripper,

Just use it, to transport a dataset it is by instance

session.Item("ds") = ds

And to use it in your other page
ds as dataset = DirectCast(session.Item("ds"),DataSet)

Cor
 
R

RipperT

Thank you for the help.

Rip

Cor Ligthert said:
Ripper,

Just use it, to transport a dataset it is by instance

session.Item("ds") = ds

And to use it in your other page
ds as dataset = DirectCast(session.Item("ds"),DataSet)

Cor
 

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

Top