Click here to Skip to main content
Click here to Skip to main content

Master Pages

, 11 Oct 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
One of the great additions to ASP.NET 2.0 is Master Pages. Master Pages help us build a consistent and maintainable UI throughout a site. A master

Editorial Note

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

One of the great additions to ASP.NET 2.0 is Master Pages. Master Pages help us build a consistent and maintainable UI throughout a site.

A master page can be created to hold those page elements that represent the common look and feel of a website. Various page elements that you might normally have added to each content page (banners, footers, menus, stylesheet links etc...) can instead be placed in the master page.  When a new content page is created, the developer simply needs to link it to an existing master page.  When that content page is rendered, the content page and its associated master page will be "merged" at runtime.  The resulting markup will contain all of the elements from the master page as well as those elements defined in the content page.

Since it is possible for many site pages (or even all site pages) to refer to a single master page, it becomes very easy to create a common look and feel for all pages in a website. It is also possible for a single site to contain multiple master pages.

The ability to group common look, feel, and functionality into a master page also saves considerable time in maintenance. For instance if you need to change the logo at the top of a page, or the copyright information at the bottom, you will only need to do it in one place. Since each content page inherits all the master page attributes, the pages are all updated one the one edit to the master page. Master pages can save development time. 

To setup a page to use a master page, add a MasterPageFile reference to the @Page directive.  Alternatively, to apply a master page at the site level (only have to specify it once), use the <pages> element to set the masterPageFile to the path of the master page.

Articles/Blogs

 

Videos

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

ASP.NET Community

United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.
 
The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
Group type: Collaborative Group

247 members


Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 11 Oct 2013
Article Copyright 2013 by ASP.NET Community
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid