0
votes

I've read in another question here how could I use custom CSS within my Sharepoint WebPart. So I followed this link:

http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=42

And I put my css as an embedded resource. Everything ok, I launch the page.

But my style doesn't appear.

I peek at the source code, and I find my resource:

<script src="/WebResource.axd?d=YuTREer2woiGbjiSaZdP0bLrdm6vpTygUffdwMFJr0zmn76B3vav0QRpmxzvYvKzZRnmgKpNbLHpnJf-W4rfrv-MrIZEoz6tWi5xHXTiN3lcxdP3s7ysDExW-eBQTlH8cUrMRw2&amp;t=634369276247430484" type="text/javascript"></script>

Which leads me to my css:

.webPartContainer
{
    background-color:Aqua;
}

.webPartContainer .Text
{
    font-size:xx-large;
}

And here's where it references the styles:

<td class="ms-WPBorder" valign="top">
    <div WebPartID="2109154d-6921-46ac-84d4-8ce24a926617" HasPers="false" id="WebPartctl00_m_g_2109154d_6921_46ac_84d4_8ce24a926617" width="100%" class="ms-WPBody" allowDelete="false" allowExport="false" style="" >
        <div id="ctl00_m_g_2109154d_6921_46ac_84d4_8ce24a926617">
        <div class="webPartContainer">
            <span class="Text">Hello World with container!</span>
            </div>
    </div>
    </div>
</td>

What's possibly happening ?

Thanks in advance !

EDIT: CssRegistration gives me permission errors, why ?

1
I don't know SharePoint, but I guess the CSS somehow isn't being loaded. Perhaps you have a wrong path somewhere? Try checking with Firefox+Firebug+Net Panel to see which CSS files are actually being loaded.thirtydot
You're right, I checked with Firebug and the CSS is not there. I just have no idea why it's not there.Conrad Clark

1 Answers

1
votes

The browser don't expect the content of a <script type='text/javascript'> tag to be CSS. So you should change your code to something like this:

string tempLink= "<link rel='stylesheet' text='text/css' href='{0}' />";
string location = Page.ClientScript.GetWebResourceUrl(this.GetType(), "myStyleSheet.css");
LiteralControl include = new LiteralControl(String.Format(tempLink, location));
Controls.Add(include);