Operate the server controls on the master page

Source: Internet
Author: User
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 " ;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.