Default ContentPlaceHolder content in Asp.Net MasterPages#

Last year, I re-designed our corporate web site to use the MasterPages feature in what was then the Beta version of Visual Studio 2005. I did not bother to read the documentation (which is a testament to their ease-of-use) and if I had, I might have discovered how default template placeholders work.

 

Like a lot of folks, I created a Master Page first and then created web forms that "used a selected master page". When you create a new form in this way, content panels which correspond to each of the Master Page's ContentPlaceholders are automatically inserted into the page. The next step is obviously to add a bunch of page-specific content into each panel. This was very intuitive and for me, my efforts were well rewarded when I later changed the layout of my master page and everything fell into place.

 

At last week's Orlando .Net User Group (ONETUG) meeting here in Orlando, Microsoft's Keith Smith gave a really great presentation on Master Pages and Atlas. He demonstrated how to add content into the ContentPlaceHolders of the Master Page, then, by simply omitting the corresponding content panel on a detail page, the (default) content of the Master Page's ContentPlaceHolder is rendered in its place.

 

Since I had gotten into the habit of adding an empty ContentPlaceHolder to the Master Page then updating each web form with the corresponding content, I might never have realized that the ContentPanel on each form is optional. A few months ago, in fact, I systematically updated every one of my web pages with a ContentPanel corresponding to a new ContentPlaceHolder. Ironically, most of the new content panels received the same user control which, of course, could have been the default content of my new ContentPanel.

 

Live and learn!

 

Going the other way, I had a situation where I needed to get rid of obsolete Content Panels on my web pages. Each of my pages included a content panel into which I had placed an image control with a unique graphic for the page.  When I deleted the corresponding ContentPlaceHolder from the master page, each of my pages complained that the ContentPanel had an invalid ContentPlaceHolder attribute. While I would ultimately want to visit each page and delete that ContentPanel (or recycle it with different content), I was able to instantly omit the content by restoring the ContentPlaceHolder in my master page and placing it into a hidden Panel Control.

 

 

 

 

4/8/2006 7:00:40 PM (Eastern Standard Time, UTC-05:00) #    Comments [0]  | 

 

All content © 2008, Brian Mishler
On this page
This site
Calendar
<July 2008>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
Archives
Sitemap
Blogroll OPML
Disclaimer

Powered by: newtelligence dasBlog 1.8.5223.2

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts


Pick a theme: