How To Pass Dynamically created value into another page..?

后端 未结 1 1042
生来不讨喜
生来不讨喜 2021-01-25 14:05

i am dynamically create contents and buttons into my code behind \"tree.aspx.cs\" page

sbmainTbl.AppendFormat(\"
相关标签:
1条回答
  • 2021-01-25 14:12

    To pass pass values using asp.net you need to follow the asp.net way.

    First on the first page you place that value on a page control, I prefer on your case a hidden field, that is also post back to any page.

    Then you add your value to that field

    ValueHiddenField.value = CellText(dtparent.Rows[0]["UnitName"].ToString())
    

    and you make also a public field so the second page can read it

    public string ValueHiddenField
    {
        get
        {
            return ValueHiddenField.value;
        }
    }
    

    And you say to the button to post back to the second page using the PostBackUrl field of the button.

    Now this is the way you get your data from second page:
    On the redirect page declare what is the previous page on aspx as:

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

    and on code behind on second page you get the value as:

    if (Page.PreviousPage != null)
    {
        if (Page.PreviousPage is PreviousPageClassName)
        {
            Label1.Text = ((PreviousPageClassName)Page.PreviousPage).ValueHiddenField;
        }
        else
        {
            Label1.Text = "no value";
        }
    }
    else
        Label1.Text = "no value from previous page";
    

    Similar answers: cross page posting
    Cross-page posting. Is it a good pratice to use PreviousPage in Asp.net?

    0 讨论(0)
提交回复
热议问题