The master page is a simple method for providing templates. Program Any number of ASP. NET pages are used. When running, the ASP. net engine merges the elements of the master page and content page into one page and displays them to the terminal.
How do I operate controls on the master page on the Content Page?
First, let's look at the events that can be used to process the master page and content page, and the trigger sequence of related events when the end user requests a content page:
Master page sub-control initialization: First Initialize all server controls contained in the master page
Initialization of the Content Page sub-control: First Initialize all server controls contained in the Content Page
Content Page initialization: Initialize the content page
Content Page loading: loads the content page, which is the page_load event following the page_loadcomplete event
Loading the master page: load the master page, which is the page_load event following the page_loadcomplete event
Master page sub-Control Loading: load the server control on the master page to the page
Content Page sub-Control Loading: load the server control on the master page to the page
After reading the event trigger sequence above, we can know that the control on the master page needs to be obtained in page_loadcomplete.
If the master page contains a lable with the ID label1 and needs to be accessed on the content page, you can do this: Protected Void Page_loadcomplete ( Object Sender, eventargs E)
{
String Masterlabel = (MASTER. findcontrol ( " Lable1 " ) As Label). text;
}
In addition, I think the better way is to expose the controls on the master page as public attributes. PublicLabel masterlabel1
{
Get{ReturnLabel1 ;}
Set{Label1=Value ;}
}
On the content page, the operation on this public property is OK. master. masterlabel1.text = " Empty " ;