ASP.NET Web Forms - Master Page
Use ASP.NET master pages to create a consistent layout for the pages in your application.Master pages provide templates for other pages on your website.
master page
Master pages allow you to create consistent appearance and behavior for all pages (or groups of pages) in your web application.
Master pages provide templates for other pages, with shared layout and functionality. Master pages define placeholders for content that can be overridden by content pages. The output is a combination of master page and content page.
Content pages contain the content you want to display.
When a user requests a content page, ASP.NET merges the pages to produce an output that combines the master page layout and content page content.
Master page example
<%@ Master %><html><body><h1>Standard Header From Masterpage</h1><asp:ContentPlaceHolder id="CPH1" runat="server"></asp:ContentPlaceHolder></body></ html>The master page above is a plain HTML template page designed for other pages.
The @Master directive defines it as a master page.
The master page contains the placeholder tag <asp:ContentPlaceHolder> for individual content.
The id="CPH1" attribute identifies the placeholder and allows multiple placeholders in the same master page.
This master page is saved as "master1.master" .
Note: Master pages can also contain code, allowing for dynamic content.
Content page example
<%@ Page MasterPageFile="master1.master" %><asp:Content ContentPlaceHolderId="CPH1" runat="server"><h2>Individual Content</h2><p>Paragraph 1</p><p>Paragraph 2</p></asp:Content>The content page above is one of the independent content pages in the site.
The @Page directive defines it as a standard content page.
The content page contains the content tag <asp:Content> , which references the master page (ContentPlaceHolderId="CPH1").
This content page is saved as "mypage1.aspx" .
When the user requests the page, ASP.NET merges the master page with the content page.
Note: The content text must be inside the <asp:Content> tag. Content text outside of tags is not allowed.
Content page with controls
<%@ Page MasterPageFile="master1.master" %><asp:Content ContentPlaceHolderId="CPH1" runat="server"><h2>W3CSchool</h2><form runat="server"><asp:TextBox id= "textbox1" runat="server" /><asp:Button id="button1" runat="server" text="Button" /></form></asp:Content>The content page above demonstrates how to insert a .NET control into the content page, just like inserting it into a normal page.
The above is the content related to the ASP.NET master page, which effectively implements the modularization of interface design and realizes code reuse.