Effective means of less repeated code-master page

Source: Internet
Author: User

The page code that inherits the motherboard page:

<% @ Page Title = "Home Page" Language = "C #" MasterPageFile = "~ /Site. master "AutoEventWireup =" true"
CodeBehind = "Default. aspx. cs" Inherits = "MasterPageAp. _ Default" %>

General Page code:

<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "WebForm1.aspx. cs" Inherits = "MasterPageAp. WebForm1" %>

 

The biggest difference is the MasterPageFile attribute.

The master page can be nested in the master page

 

Access controls and properties on the master page
1. Use the Master. FindControl method to access the control on the Master page
2. reference the @ MasterType command to access the attributes on the master page.

Note the code placement location:
Before the Page_load event of the master page is triggered, the Page_load event of the content page has been triggered.

Controls on the master page are difficult. This example uses the Page_loadComplete event added by ASP. NET and the FindControl party

To obtain the control of the master page. The Page_LoadComplete event is triggered at the end of the web page loading within the lifecycle. Of course

You can also complete this function under the PreRender event of the Label control.

 

 

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.