YouTip LogoYouTip

Aspnet Masterpages

# 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 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 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 produce output that combines the master page layout with the content page content. * * * ## Master Page Example

Standard Header From Masterpage

The master page above is a regular HTML template page designed for other pages. The **@ Master** directive defines it as a master page. The master page contains a placeholder tag **** for individual content. The **id="CPH1"** attribute identifies the placeholder, allowing multiple placeholders in the same master page. This master page is saved as **"master1.master"**. ![Image 3: lamp](#) Note: Master pages can also contain code, allowing dynamic content. * * * ## Content Page Example

Individual Content

Paragraph 1

Paragraph 2

The content page above is one of the individual content pages in the site. The **@ Page** directive defines it as a standard content page. The content page contains a content tag **** that references 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](#) ![Image 4: lamp](#)Note: Content text must be placed inside the tags. Content text outside the tags is not allowed. * * * ## Content Page with Controls

TUTORIAL

The content page above demonstrates how to insert .NET controls into a content page, just like inserting them into a regular page. [Click here to display mypage2.aspx](#)
← Ng Ng CheckedNg Ng Change β†’