Master Pages





0/5 (0 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
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.
-
ASP.NET Master Pages Overview - An overview of Master Pages article on MSDN
-
Tips, Tricks and Traps of Master Pages and their solution - A blog which discusses many of the tips, tricks and traps of using Master Pages
- MasterPage and Viewstate relationship