cross page posting

后端 未结 1 471
独厮守ぢ
独厮守ぢ 2020-12-20 01:53

i am just trying the example of cross page posting. i have added 1 textbox & 1 button to default.aspx page



        
相关标签:
1条回答
  • 2020-12-20 02:16

    If you have master page then the code Page.PreviousPage.FindControl("TextBox1"); not work because the TextBox1 is under the ContentPlaceHolder. and must first locate the ContentPlaceHolder. and then find the TextBox1

    But there is an easiest way to get the value as:

    Place this on the previous page:

    public string TextFromBox1
    {
        get
        {
            return TextBox1.Text;
        }
    }
    

    and on the redirect page declare what is the previous page on aspx as:

    <%@ Reference Page ="~/PreviousPageName.aspx" %>
    

    and on code behind get the value as:

    if (Page.PreviousPage != null)
    {
        if (Page.PreviousPage is PreviousPageClassName)
        {
            Label1.Text = ((PreviousPageClassName)Page.PreviousPage).TextFromBox1;
        }
        else
        {
            Label1.Text = "no value";
        }
    }
    else
        Label1.Text = "no value from previous page";
    
    0 讨论(0)
提交回复
热议问题