By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,625 Members | 1,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,625 IT Pros & Developers. It's quick & easy.

Passing DataTable Across ASPX Pages

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
"Eric" <No*@y.Josť> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.