Passing Variables between pages

Hobbes

Active member
Joined
May 22, 2003
Messages
37
Hello.

I am a newbie in ASP.net. I am learning it own my own and faces many problems, even with 3 books.

My Question: Is there a way to pass variables between pages and display the information on another page?

I am trying to allow user to enter a message in a textbox and then display it on another page before e-mailling it to me.

Thanks!

:confused:
 
You have several choices in how to do that.

The first is to append it to your redirect call as a query string and then retrieve the value.
[VB]
Public Class Page1
Dim searchParams as string

Private Sub GoToPage2()
searchParams = "Param1=" & httputility.urlencode(MyTextbox.Text)
searchParams += "&Param2=" & httputility.urlencode(Textbox2.Text)
response.redirect("Page2.aspx?" & searchParams
End Sub

End Class

Public Class Page2

Private Sub GetValue()
NewTextBox.Text = request.Params("Param1")
NewTextBox2.Text = request.params("Param2")
End Sub

End Class
[/VB]

Or pass the value as explained in:
http://msdn.microsoft.com/library/d...ml/vbtskpassingvaluesbetweenwebformspages.asp

Two ideas are enough. Though, I would recommend the first anway.

Eva
 
Method 2 comes in handy if youre not using response.redirect(), especially if you want to pass objects from page to page and not just strings.
 
Back
Top