摘要:[ASP.net Web] 頁面跳轉-Cross-Page Posting
Cross-Page Posting
目的
將 Textbox 的值透過 Main.aspx 傳至 Method1.aspx 或 Method2.aspx。
Main.aspx.cs
元件包含1個 Textbox (id 為 input )與二個 Button(id 分別為 Button1 與 Button2)。
Main.aspx.cs
public TextBox shareinput { get; private set; }
protected void Page_Load(object sender, EventArgs e)
{
shareinput = input;
}
Method1c.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
TextBox textbox = new TextBox();
if (PreviousPage == null && !IsCrossPagePostBack)
{
Response.Write("沒有來源網頁");
}
else
{
textbox = (TextBox)PreviousPage.FindControl("input");
Response.Write(textbox.Text);
}
}
Method2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Method2.aspx.cs" Inherits="Damo.Method2" %>
<%@ PreviousPageType VirtualPath="~/Main.aspx"%>
Method2.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage == null && !IsCrossPagePostBack)
{
Response.Write("沒有來源網頁");
}
else
{
Response.Write(PreviousPage.shareinput.Text);
}
}
以上有任何問題與錯誤,歡迎各位指教,謝謝。