利用@PreviousPageType指令完成,
举例:Page1.aspx:
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" PostBackUrl="~/Page2.aspx"
Text="提交到Page2" />
</div>
Page1.aspx.cs:
public string UserName
{
get{return this.TextBox1.Text;}
}
Page2.aspx:
<%@ PreviousPageType VirtualPath="~/Page1.aspx" %>
Page2.aspx.cs:
if (this.PreviousPage != null)
{
this.Response.Write(this.PreviousPage.UserName);
}