2
我有兩個頁面。 first.aspx和second.aspx。爲了得到first.aspx所有的控制值,我添加指令second.aspx即使在ASP.NET中,頁面加載後私有變量的值也不會保留
<%@ PreviousPageType VirtualPath="~/PR.aspx" %>
我沒有問題,讓以前所有的頁面控件並將其設置爲標籤,但我有一個很大的問題將這些值保存到私有變量,並在頁面加載事件完成後重新使用它。這裏是代碼示例。當我嘗試從另一個方法的輸入中獲取值時,它沒有添加任何內容。爲什麼?
public partial class Second : System.Web.UI.Page
{
List<string> input = new List<string>();
protected void Page_Load(object sender, EventArgs e)
{
if (Page.PreviousPage != null&&PreviousPage.IsCrossPagePostBack == true)
{
TextBox SourceTextBox11 (TextBox)Page.PreviousPage.FindControl("TextBox11");
if (SourceTextBox11 != null)
{
Label1.Text = SourceTextBox11.Text;
input.Add(SourceTextBox11.Text);
}
}
}
protected void SubmitBT_Click(object sender, EventArgs e)
{
//do sth with input list<string>
//input has nothing in it here.
}
}
感謝蒂姆。現在我明白了問題所在。 – John 2013-02-19 21:58:21