tags:

views:

115

answers:

4

i am very new to asp.net. when someone presses a button on default.aspx, this takes a user to default2.aspx by response.direct. there are some local variables on default.aspx that i want to carry over to the next page. i want to know what their values are. for example if someone entered text in a textbox on the default.aspx i would like to know that value on the next page. thank you so much for your time.

+1  A: 

You could use SessionState

Andrew Garrison
+4  A: 

It sounds like you are looking for cross-page postbacks.

Getting Information from the Source Page

When you configure a page for cross-page posting, you frequently want to get information from the source page. This might include the information from controls on the page—that is, the information being posted by the browser—as well as public properties of the source page.

Getting Control Values

The Page class exposes a property named PreviousPage. If the source page and target page are in the same ASP.NET application, the PreviousPage property in the target page contains a reference to the source page. (If the page is not the target of a cross-page posting, or if the pages are in different applications, the PreviousPage property is not initialized.) By default, the PreviousPage property is typed as Page.

Andrew Hare
I agree. The PreviousPage property can also be accessed when a Server.Transfer is performed too.
RichardOD
I believe that Server.Transfer forwards the request along to the new page, so you don't need to do anything special to access the posted values.
chris
+2  A: 

You could use Session or Page.PreviousPage.FindControl("previousPageTextBox");

IE:

TextBox myTxt = (TextBox)Page.PreviousPage.FindControl("previousPageTextBox");   
currentPageTextBox.text = myTxt.Text;
Jreeter
+1  A: 

It sounds like you want to use Server.Transfer rather than Response.redirect.

You should NOT use the session to preserve request variables, because if there's always the chance that users are going to have multiple tabs open.

chris