Get post values between two pages


L

Luigi

Hi all,
in an aspx Page_Load event, how can I get a textbox value taken from the
previous page?

Example
Page1.aspx with textbox and button that redirect to Page2.aspx

In this page I'd like to set a label with the textbox value from the first
page.

Thanks a lot.

Luis
 
Ad

Advertisements

L

Luigi

:
Several ways, but the two simplest are:
1) Pass it as a QueryString name/value pair:
http://www.google.co.uk/search?aq=f&sourceid=chrome&ie=UTF-8&q=ASP.NET+QueryString

2) Use a Session variable
http://www.google.co.uk/search?hl=en&q=ASP.NET+Session+variable&btnG=Search&meta=

1) takes up no server memory, but the value is visible in the address bar
and could, in theory, be inspected or changed by the user.

2) takes up a bit of server memory (almost certainly only a tiny amount),
but the value is hidden from the user.

Thanks Mark,
I'm trying this in Page2.aspx

protected void Page_Load(object sender, EventArgs e)
{

TextBox txtbox1;
txtbox1 = (TextBox)PreviousPage.FindControl("text1");
Label1.Text = txtbox1.Text;

}

but got me an null exception (the "text1" textbox exist in Page1.aspx).

My button in Page1.aspx is:

<input type="button" value="Continue" id="button2" name="button2"
onclick="return OnButton2();" />


and

function OnButton2() {
document.URL = "Page2.aspx";
return true;
}

Maybe the problem is on javascript function?

Luis
 
Ad

Advertisements


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

Top