You can access PreviousPage if you have used Server.Transfer
, not Response.Redirect
. Here's how I would acess it:
In the first page set runat="server"
for the div:
<div id="myDiv" runat="server">My First Div</div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
And in the code behind:
protected void Button1_Click(object sender, EventArgs e)
{
Server.Transfer ("secondpage.aspx");
}
In the second page I am catching the div using FindControl
:
public partial class secondpage: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl myDiv = (HtmlGenericControl) Page.PreviousPage.FindControl("myDiv");
Label1.Text = myDiv.InnerText;
}
}
You will find details in MSDN
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…