ASP.NET Web Forms - Master Pages
Master pages provide templates for other pages on your website.
Master Pages
Master pages allow you to create a consistent look and feel for all pages (or groups of pages) in your web application.
Master pages provide templates for other pages, with shared layouts and functionalities. Master pages define placeholders that can be overridden by content pages. The output is a combination of the master page and the content page.
Content pages contain the content you want to display.
When a user requests a content page, ASP.NET merges the pages to generate an output that combines the layout of the master page with the content of the content page.
Master Page Example
The above master page is a standard HTML template page designed for other pages.
The @ Master directive defines it as a master page.
The master page includes placeholder tags <asp:ContentPlaceHolder> for individual content.
The id="CPH1" attribute identifies the placeholder, allowing multiple placeholders within the same master page.
This master page is saved as "master1.master".
Content Page Example
The above content page is one of the standalone content pages on the site.
The @ Page directive defines it as a standard content page.
The content page includes content tags <asp:Content>, which reference the master page (ContentPlaceHolderId="CPH1").
This content page is saved as "mypage1.aspx".
When a user requests this page, ASP.NET merges the master page with the content page.
Click here to display mypage1.aspx
Content Page with Controls
The above content page demonstrates how to insert .NET controls into the content page, just like in a regular page.