ASP.NET Master Page

The ability of master pages to create a unified user interface and styling for ASP.NET applications is the core function of master pages.

Comparison of master pages and normal pages :

First, the extension of the master page is .master. All files with the extension .master are master pages. The client browser can send a request to the server to access the .aspx file. However, if the request is a master page page, it cannot be executed.

Second, the code header declaration of ordinary .aspx files is <%@Page%>, and the code header declaration of master page files is different from this, it must be declared as <%@Master%>.

The third is that the master page can include one or more ControlPlaceHolder controls, which are not included in ordinary .aspx files. The ControlPlaceHolder control acts as a placeholder that identifies an area in the master page that will be replaced by specific code in the content page.



1. Use the FindControl method to get the master page control reference:

In the content page, the core object Page has a public property Master, which can implement a reference to the base class MasterPage of the relevant master page. The MasterPage belonging to the master page is equivalent to the Page object of a normal ASP.NET page. In this way, the MasterPage object can be used to achieve access to each child object in the master page. Since the controls of the master page are protected, they cannot be accessed directly and must be implemented using the FindControl method of the MasterPage.

2. Use the MasterType command to get the master page control reference:

After using the MasterType directive in the content page, the Master property in the content page will be strongly typed. That is, through the MasterType directive, it is possible to create a strongly typed reference to a master page relative to a content page. Therefore, in the content page, you can use the Master object to access the public methods, properties, controls and other members of the master page.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326080339&siteId=291194637