Search code examples
asp.netmaster-pages

How to get data from master page to child page in asp.net


Currently, in a dot net project, i have a master page & a child page. I have given various options, like textbox, combo box etc, on a master page with a submit button. Now i have a child page where i want to process the request sent by master page.

I have heard that retaincontrolstate is used like

private void retainControlState()
            {

            }

But currently i am not recieving the values from the masterpage onto the child page, not even the click event of the master page.

How can i make the click of master page button to send the request to the child page ?


Solution

  • You should:

    1. Make sure you can access the controls on your master page from the page, e.g. make them public fields
    2. In the Page_Init of your page, cast your the Master property to its proper type (or just use the MasterType directive - https://msdn.microsoft.com/en-us/library/ms228274(v=vs.100).aspx)
    3. Then you can hook up the event handler in your page to the controls on your master page

    ControlState has nothing to do with this.

    Does it make sense to handle stuff on your master page in your content page's code-behind though? Why not simply do this in the Master page's code-behind?