Passing DataTable Across ASPX Pages

E

Eric

Hello,

I am trying to come up with the best way to pass large amounts of data from
page to page, namely a data table.

The user needs to enter data into a form in one page and confirm it on
another. Session variables seem like the easiest, but I'm afraid of
crashing the server after deploying with a few hundred users as opposed to
just a few developers/testers. Any ideas?

Thanks,

Eric
 
S

S. Justin Gengo

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top