i am just trying the example of cross page posting. i have added 1 textbox & 1 button to default.aspx page
If you have master page then the code Page.PreviousPage.FindControl("TextBox1");
not work because the TextBox1
is under the ContentPlaceHolder.
and must first locate the ContentPlaceHolder.
and then find the TextBox1
But there is an easiest way to get the value as:
Place this on the previous page:
public string TextFromBox1
{
get
{
return TextBox1.Text;
}
}
and on the redirect page declare what is the previous page on aspx as:
<%@ Reference Page ="~/PreviousPageName.aspx" %>
and on code behind get the value as:
if (Page.PreviousPage != null)
{
if (Page.PreviousPage is PreviousPageClassName)
{
Label1.Text = ((PreviousPageClassName)Page.PreviousPage).TextFromBox1;
}
else
{
Label1.Text = "no value";
}
}
else
Label1.Text = "no value from previous page";