How to carry info from one page to next?

joe_pool_is

Contributor
Joined
Jan 18, 2004
Messages
507
Location
Longview, TX [USA]
From a form, how can I carry the data from one Form (say a Customer's Name) to another Form?

Example:
From Form1: (assume txtName.Text = "Herman Munster")
Code:
Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
	Server.Transfer("Form2.aspx")
End Sub
From Form2:
Code:
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
	lblName.Text = "" 
	' Can't assign to Form1.txtName.Text.
	' So how would I do this?
End Sub
 
TwistedNerve: That will only work on the currently executing page. It will not work between pages, when the Context.Items collection will be flushed, unless Server.Transfer() is being invoked, which is a problem that needs fixing in and of itself.
 
Derek Stone: Yes, I am aware that it only works when invoking Server.Transfer (I stated, "duration of the current request"), and the reason I mentioned Context.Items collection is because his code example is using the Server.Transfer method. Also, just out of curiosity, what type of problems have you run into with the transfer method? I personally dont use it, but would like to hear your thoughts.
 
TwistedNerve and Derek Stone:

I have always used Server.Transfer() to load the next page. Is there another (or better) way? I would be interested to learn how and when to use one method over another.
 
Personally... I use QueryString (from Request and Response object - depend on what you are trying to do, read or write) if the data isn't DataBase linked and or it doesn't matter if the user modify it (like email, name, first name, etc....)

If the Data is sensible or that is linked to a DB and it would REALLY be a problem if the user modify something (validated data) then I use the Session object (that is unique to each user).

Want more info ? Ask on this thread ! :)
 
joe_pool_is: In all but a very few situations, such as wizards and authentication/authorization redirects, you should instead be using Response.Redirect().

Server.Transfer() has its place, but it is very defined and limited. It should be used when the current request is part of a series of requests (such as a "new user" wizard), where the user shouldn't be navigating to any portion of the wizard directly (it's an all or nothing process, either complete the wizard at that time or don't at all). It should also be used when the user is being denied access to a resource (HTTP response code 401/403), at which time the client shouldn't be given a chance to redirect (HTTP response code 301/303).

For all other situations Response.Redirect() is more appropriate. It clearly notifies both the browser and the user of the change in pages. The URL will be updated on the client, the browser's history will reflect the user's location accurately, and most importantly the page will be executing in the intended context.
 
Back
Top