Skip navigation.

How Much Room For Error Have You Built Into Your Business?All recent postsHow to Create a Multi-Tiered Web Application in Visual Studio 2005

How to Link Stylesheets from a Master Page (Part 2)

The omnipresent Scott Guthrie has descended upon this blog to set the record straight: the header control was ordained with magical powers of URL rebasing in pre-existence! If you pull out your dusty magnifying glass and pore over Scott’s comment, note this key phrase: relative to the master page location. I guess no need to use my property hack in the head, although it comes in handy in the rest of the master page.

And then Scott Allen steals the thunder again: what if you put a ContentPlaceHolder right in the head? Good idea.

<asp:ContentPlaceHolder id="AdditionalHeaderEntries" runat="server">
</asp:ContentPlaceHolder>

If I need to declare page-scope CSS rules or link to an external JavaScript file, I can do it selectively on every page that needs extra beef:

<asp:Content
     ContentPlaceHolderID="AdditionalHeaderEntries"
      runat="server">

<style type="text/css" media="all">
   h1 { 
     text-align: center; 
     line-height: 1.3em; 
     margin-top: 0.5em; 
    }
</style>
</asp:Content>

Many thanks to Scott and Scott for the discussion.

Comments

Comment permalink 1 kl |
Yes, I've used ContentPlaceHolder as well. The markup editor complains about it but it works. I hope that ContentPlaceHolders will continue to be valid in the HEAD in future.
Comment permalink 2 Michael Schøler |
And why is this possible in the tag without any problems?

<% Response.Write(this.sHeadTitle); %>
Comment permalink 3 Michael Schøler |
HTML formatted comment-code is stripped by this blog apparently, I wonder how you other guys got your code through?...

Oh well, you can insert Response.Write inside the title head section without any problems. Odd.
Comment permalink 4 Milan Negovan |
Michael, Response.Write produces a literal string, so the runtime won't see it, AFAIK. Also, it won't touch the head element. The issue is with rebasing URLs, i.e. external JavaScript and CSS files.

Emails and Notifications

Would you like to be notified when somebody responds to this post?  Would you like to have these comments emailed to you?

TrackBacks

Sorry, TrackBacks are not allowed.

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):