asp.net CROSS-PAGE POSTING
有两个页面page1和page2。page1中有两个按钮
<asp:Button ID="Button1" runat="server" Text="Submit page to itself"
OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Submit page to Page2.aspx"
PostBackUrl="Page2.aspx" />
Button1 post给自己、Button2 post给page2,注意到Button2没有OnClick事件。而是PostBackUrl属性来说明他要提交到哪一页。如下图所示
在page2中如何获取page1中页面的值呢?代码如下
protected void Page_Load(object sender, EventArgs e)
{
TextBox pp_TextBox1;
Calendar pp_Calendar1;
pp_TextBox1 = (TextBox)PreviousPage.FindControl("TextBox1");
pp_Calendar1 = (Calendar)PreviousPage.FindControl("Calendar1");
Label1.Text = "Hello " + pp_TextBox1.Text + "<br />" +
"Date Selected: " + pp_Calendar1.SelectedDate.ToShortDateString();
}
这样在page2的page_load事件中就可以获取到page1中两个控件的值。当然也可以通过下面判断当前回发是自身控件引起的还是其他页面post过来的。
The IsCrossPagePostBack property enables you to check
whether the request is from Page1.aspx
if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)