Eric,
You may use Server.Transfer to make the previous page's context available.
Here's some sample code from the code library on my site:
Use Server.Transfer to pass values from one page to another
If you don't want to use session variables or have data appear in the query
string of your page then utilizing the Server.Transfer method for moving
from one page to another is a great way to make one page's properties
available to another.
Sample Code:
'---On your first page create a public property that accesses the value you
want to make accessible to other pages.
Public ReadOnly Property UserId() As Int32
Get
'---Where _UserId is a private variable on the page
Return _UserId
End Get
End Property
'---Use Server.Transfer to execute the page transferred to.
Private Sub SubmitButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SubmitButton.Click
Server.Transfer("page2.aspx")
End Sub
'---Recreate the page1 object on page2 and get the user id.
Private _UserId As Int32
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim Page1 As Page1 = CType(Context.Handler, Page1)
_UserId = Page1.UserId
End If
End Sub
If you're going to have multiple pages that you could be arriving at another
page from you will also need to be able to tell which page the user has
arrived from before you may correctly cast the context object.
The way to do that is:
Server.Transfer - Get the name of the page transferred from
When Server.Transfer is used it allows access to the previous page's
variables, but you have to re-create the previous page by performing CType()
on the context object.
This is fine if users can only move to a new page from one single place, but
if a user can arrive at the same page from multiple pages how do you know
which page the context is arriving from? If you don't you can't recreate the
previous page to access its variables.
This code get's the name of the previous page.
Then you can perform a Select Case based on page name to re-create the
previous page from the context object.
Sample Code:
Public Class GetTransferredContextPageName
Public Function GetPageName(ByVal ContextTransferred As
System.Web.HttpContext) As String
Try
Dim Page As Object = ContextTransferred.Handler
Dim PageName As String = LCase(Page.GetType.ToString)
PageName = Replace(PageName, "_aspx", "")
PageName = Replace(PageName, "asp.", "")
Return PageName
Catch e As Exception
Throw e
End Try
End Function
End Class
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche