ASP.NET Master Page
A Master Page enables you to share the same content among multiple pages in a website. The master page defines placeholders for the content, which can be overridden by content pages. The output result is a combination of the master page and the content page. This improves the maintainability of your site and avoids unnecessary duplication of code for shared site structure or behaviour.
Defining a Master page is similar to defining a normal page, but saving a Master page is different from saving a normal page. You must save the Master pages by using the .master file extension. Master pages are completely transparent to end users and permit developers to create Web sites where pages share a common layout. The page layout for Master Pages is easy to create, simple to maintain, and simple to assign to a Web application. The master page is identified by a special @ Master directive that replaces the @ Page directive that is used for ordinary .aspx pages.
Features of MasterPage
- The extension of MasterPage is '.master'.
- MasterPage cannot be directly accessed from client because it just acts as a template for the other Content Pages.
- In a MasterPage we can have content either inside ContentPlaceHolder or outside it. Only content inside the ContentPlaceHolder can be customized in the Content Page.
- We can have multiple masters in one web application.
- A MasterPage can have another MasterPage, MasterPage can be nested
- Controls of MasterPage can be programmed in the MasterPage and content page but a content page control will never be programmed in MasterPage.
- A master page of one web application cannot be used in another web application.
- The MasterPageFile property of a webform can be set dynamically and it should be done either in or before the Page_PreInit event of the WebForm. Page.MasterPageFile = "MasterPage.master". The dynamically set Master Page must have the ContentPlaceHolder whose content has been customized in the WebForm.