Welcome to MSDN Blogs Sign in | Join | Help

Examining Master Pages

Over the years Web developers have struggled with a variety of techniques to try and create template based sites. Unfortunately, none of these have been generic and easy to maintain. The introduction of Master pages is designed to solve this problem.

 

Conceptually master pages consist of two elements: Master Page and Content Page. Master pages act as the templates for the Content Pages, and Content Pages provide content to populate pieces of Master Pages. A Master Page is essentially a standard ASP.NET page except that it used the extension of .master and a <%@ master %> directive instead of <%@ page %>. This Master Page file serves as the template for other pages, so typically it will contain the top-level HTML elements, the main form, headers, footers, and such. Within the Master Page you add instances of the ContentPlaceHolder control at locations where you want Content Pages to supply page-specific content.

 

The Content Pages are just ordinary .aspx files that specify an associated Master Page in their page directive using the masterpagefile attribute. These pages contain only instances of the Content control as they are used to to supply content for the inherited Master Page template. Each Content control must map to a specific ContentPlaceHolder control defined in the referenced Master Page, the contents of which is inserted into the Master Page's placeholder at rendering time.

 

In this screencast available here we examine some of the uses for Master Pages within your application.

 

<<View Examining Master Pages>>

Published Sunday, December 18, 2005 8:03 PM by trobbins

Comments

# re: Examining Master Pages

Sunday, December 18, 2005 11:35 PM by James Hancock
Master Pages is great... except that it is completely un-Search Engine friendly. I had to create a hack to get around this HUGE oversite:

You can't set the Keyword or Description meta tags or any other meta tags for that matter (although others would be of minor use except maybe the refresh command) per child page.

Thus you can't customize the keywords and description (you can the title) per page, thus making, out of the box, Master Pages useless for anyone that actually wants to get search engine hits.

Scooble just had an article about the XBOX 360 and how wondeful it is in HDTV and I pointed out there that XB0X 360 still blows it because it doesn't provide HDMI/DVI output thus providing technology that is years out of date for people that will have the technology (i.e. if you've bought a TV in the last 2 years, it came with a DVI or HDMI port and you'd no doubt wnat to hook up your brand new HDTV ready XBOX 360 to it... but you can't!

Same deal with Master Pages, and the bugs in URL Re-writting and the horrible Management Studio in SQL Server 2005. In every major product anouncement in the last 6 months from MS there have been such glaring ommissions and failures to execute that it's absolutely mind-numbing. I hope that Vista doesn't get infected with this lack of execution recursive virus that seems to have infected all of MS's development teams lately....

# re: Examining Master Pages

Monday, December 19, 2005 3:02 PM by Jarred Nicholls
I just want to point out to James Hancock that Content Pages have an HtmlHead property that you can add HtmlMeta objects to, thus voiding your claim and solving this "HUGE oversite". That is all.

# re: Examining Master Pages

Friday, December 23, 2005 2:19 AM by James Hancock
Unless I'm missing something (and I don't think I am because people at MS said you couldn't do it, so...) you still can't set it in your markup, you have to do it in the code behind (or have ugly <%%> stuff in your page. End result is if you're creating a framework for others to use, you're still screwed.
New Comments to this post are disabled
 
Page view tracker