Vault of Thoughts


Please visit my new blog at

Master Page ContentPlaceHolder inside head element

Today I have been struggling with a typical table layed out page. It was a MasterPage with few ContentPlaceHolder controls - one for content, one for menu and few for other things. The problem was that the place holders were inside the td elements and some of the elements were made in such a way that they dropped shadow (background-image) and it was not possible from the content page to override this behavior (at least not in a clean way). First I have tried to override the style which made the cell to have an image at the bottom by adding the style element inside one the contents. Unfortunatelly it is not valid html to do so. Then I have thought about adding a ContentPlaceHolder inside the head element. Unfortunatelly Visual Studio does not provide the ContentPlaceHolder control in the intellisense so I thought that it will not wokr... But it did!!!

What is a very good thing to know is that despite the VS not telling you about it, you can put a ContentPlaceHolder inside the head element. You can work with it just like with any other ContentPlaceHolder by providing default content for example. It can also be used as a place for additional page level style elements. One great feature that VS DOES provide is the fact that in the content page, when you edit the head ContentPlaceHolder, you get the intellisense for the head element so you wont see any divs or other body elements there.

After this discovery I have made a search on google to find if anyone had the same problem and I have found the following: artcle.

kick it on

If you liked this article why not support its author by making a donation?


  • Nice Blog Michal, Please contact me via: about your blog.


    By Anonymous Anonymous, at 4:45 PM  

  • You have to be careful using the contentplaceholder control within a head tag with the runat=server attribute. If you try to use set the Title in your page, you will see that the parsing doesn't work as you'd expect and the resulting html title tag often wraps the content contained within the contentplaceholder. This leads to some very strange page titles.

    Matt Howeson websites for sports clubs

    By Blogger mhoweson, at 3:57 PM  

  • This comment has been removed by the author.

    By Blogger Triynko, at 11:10 PM  

  • UPDATE: In Visual Studio 2010, it now puts a "head" ContentPlaceHolder in the head tag by default when you create a new master page! It's the only other placeholder that's there by default besides the main "content" placeholder. Interestingly, they add the "head" placeholder *after* the title tag, perhaps to eliminate the problem mentioned above.

    By Blogger Triynko, at 11:12 PM  

Post a Comment

Links to this post:

Create a Link

<< Home