Tag: scriptregistration

CSSRegistrations and ScriptRegistration in SP 2010

The CssRegistration control adds each of the style sheets to an internal collection in the SPContext and the CssLink renders each of them in alphabetical order before rendering the primary, default, and alternate CSS links. If you want one of them to appear after core.css, set the DefaultUrl property of CssLink.

CSSLink Example:

<Sharepoint:CssLink runat="server" DefaultUrl="<% $SPUrl:~SiteCollection/Style Library/en-us/Core Styles/Style.css %>"/>

CssRegistration Example:

<SharePoint:CssRegistration Name="<%$ SPUrl:~sitecollection/Style Library/en-us/Core Styles/Style.css %>"
After="corev4.css" runat="server" EnableCssTheming="true"/>

It’s very easy to get confused by this because the CssRegistration controls are after CssLink, but they don’t render the links, CssLink does!
One advantage that the publishing definitions have over the SharePoint default.master is the $SPUrl expression that allows dynamic creation of the URL for sites under the root web that use the root web’s master pages. Unfortunately, while CssRegistration is part of the core Microsoft.SharePoint.dll, $SPUrl requires the publishing features to be turned on.

For a JS reference, it’s important to note that ScriptLink doesn’t support the expression builders like . If the script available in top-Level site, you can use:

<SharePoint:Scriptlink runat="server" name="~SiteCollection/Style Library/en-us/Core Styles/JS/script1.js" 
language="javscript" />

If the script avaialble in the current site, we can use:

<SharePoint:Scriptlink runat="server" name="~Site/Style Library/en-us/Core Styles/JS/script1.js" 
language="javscript" />