@ Master: defines ASP. NET page analyzer and compiler attributes specific to the master page (. Master file. For details, see the MSDN attributes.
1. Create a simple nested master page
First, create a master page as the master page, then create a new master page, and select the master page as the master page to complete the nesting, which is mainly applied to the nested category master in the master website.
2. Access the controls on the master page
Master: obtains the parent Master page of the current Master page in the nested Master page solution.
FindControl: Search for the server control with the specified id parameter in the current named container.
1 protected void Page_LoadComplete (object sender, EventArgs e)
2 {
3 Label mlabel = (Label) this. Master. FindControl ("labMaster ");
4 this. Label1.Text = mlabel. Text;
5}
6
3. Access the properties on the master page
Define a public attribute in the cs code on the master page.
String mValue = "";
Public string MValue
{
Get
{
Return mValue;
}
Set
{
MValue = value;
}
}
You can reference this attribute in the source code of the master page and place it in any location. <% = this. MValue %> can also be displayed using controls.
Add <% @ MasterType VirtualPath = "MasterPage. master "%>: provides a method for accessing ASP. NET master page, create a strong type reference to the master page.
In the cs code on the content page
Protected void Page_Load (object sender, EventArgs e)
{
Master. MValue = "Welcome ";
}