Page view counter

Adding CssClass attribute to ContentPlaceHolder

Last post 10-29-2006 5:30 PM by mbanavige. 3 replies.

Sort Posts:

  • Adding CssClass attribute to ContentPlaceHolder

    10-29-2006, 3:52 PM
    • Loading...
    • kreid
    • Joined on 10-19-2006, 12:15 PM
    • Posts 87

    It seems I can't add a CssClass attribute in the tag of a Content placeholder on my Master Page, eg:

                        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" CssClass="myclass">
                        </asp:ContentPlaceHolder>

    Why is this the case?

    I simply want to keep the style of my content pages abstracted from my master page.  Since adding a css file to a page also applies the styles contained therein to the related Master page, this seemed like the only alternative.
    Any ideas what I can do to solve my problem?
     
    Thanks,
    kreid
     

  • Re: Adding CssClass attribute to ContentPlaceHolder

    10-29-2006, 4:31 PM
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 8:29 AM
    • New England, USA
    • Posts 8,382
    • Moderator
      TrustedFriends-MVPs

    the ContentPlaceHolder itself does not actually render so adding a cssclass (if allowed) wouldnt have any effect.
    try it like this instead:

    <div Class="myclass">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    your page content will appear directly inside of the div
    Mike Banavige
    ~~~~~~~~~~~~

    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
  • Re: Adding CssClass attribute to ContentPlaceHolder

    10-29-2006, 4:54 PM
    • Loading...
    • kreid
    • Joined on 10-19-2006, 12:15 PM
    • Posts 87

    Ok, I understand.

    This won't affect the rendering of the stuff inside the ContentPlaceHolder though, will it? It would be ideal if I used the above div, then inside the placeholder I could just specify <h1>Heading</h1> - rendering the heading with the correct style applied (e.g.: myclass.h1).  I do not think this is possible though, so what is the best way to separate the styles of the masterpage a contentplaceholder page?

    The only idea I have is to link to the stylesheets in MasterPage.master and specify classes or ids, e.g.:

    .cmaster {font-family: Arial; font-size: 24pt; color: black; }

    .content {font-family: Verdana; font-size: 14pt; color: blue; }

     

    then in the page:

    <h1 class="content">Foo</h1>

    etc, etc... 

     

     Anyone got a better way?

     
    Thanks,

    kreid
     

  • Re: Adding CssClass attribute to ContentPlaceHolder

    10-29-2006, 5:30 PM
    Answer
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 8:29 AM
    • New England, USA
    • Posts 8,382
    • Moderator
      TrustedFriends-MVPs
    kreid:
    This won't affect the rendering of the stuff inside the ContentPlaceHolder though, will it?

    it certainly could...

    kreid:
    It would be ideal if I used the above div, then inside the placeholder I could just specify <h1>Heading</h1> - rendering the heading with the correct style applied (e.g.: myclass.h1). 

    it would be "myclass h1" which would affect any h1 tag found inside the class myclass. when you use the dot (myclass.h1) you are affecting an h1 contained directly insie the class myclass.

    Mike Banavige
    ~~~~~~~~~~~~

    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
Page 1 of 1 (4 items)
Microsoft Communities