ASP.NET how to access public properties?

前端 未结 5 696
难免孤独
难免孤独 2020-12-12 08:06

I have two pages page1.aspx and page2.aspx, both have code behind with partial classes. How do i access public property message on page1.aspx from page2.aspx ?



        
5条回答
  •  一生所求
    2020-12-12 08:36

    Update

    I just read that the one is MasterPage and the other is the client to masterpage ? then its diferent way.

    Page to Page

    If you have 2 simple diferent pages. I have done it this way. Its a post value, by using asp.net tricks :)

    On Page2.aspx add this on top.

    <%@ PreviousPageType VirtualPath="Page1.aspx" %>
    

    and how I read from Page1.aspx on code behind

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Page.PreviousPage != null)
            {
                if(Page.PreviousPage.IsCrossPagePostBack == true)
                {
                    txtGetItFromPreviusPage.Text = PreviousPage.SomeString;
                }
            }
        }
    }
    

    On Page1.aspx the button that send me to Page2.aspx

                     
    

    and the code that I use for Page1 calculations or other thinks

    public string SomeString
    {
        set 
        { 
            ViewState["txtSomeString"] = value;
        }
        get
        {
            if (ViewState["txtSomeString"] != null)
                return ViewState["txtSomeString"].ToString();
            else
                return string.Empty;
        }
    }
    
    
    protected void btnMoveSelection_Click(object sender, EventArgs e)
    {
        // some final calculations
    
    }   
    

提交回复
热议问题