. NET basic mother page application

Source: Internet
Author: User

@ 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 ";
    }

     

     

  • 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.