This topic has not yet been rated - Rate this topic

CssRegistration Class

Represents a cascading style sheet (CSS) file registration. CssLink reads this registration to insert a LINK element into the resulting HTML page and apply the external style sheet(s) defined by the registration.

System.Object
  System.Web.UI.Control
    Microsoft.SharePoint.WebControls.SPControl
      Microsoft.SharePoint.WebControls.CssRegistration

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CssRegistration : SPControl

Pages and controls register specific style sheets by using the <SharePoint:CssRegistration name="filename" tag or calling the static CssRegistration.Register("filename") method. The CSS can be registered as a leaf filename or as a URL. For example:

<SharePoint:CSSRegistration name= "<%$SPrl:~SiteCollection/Style Library/~language/Core Stypes/Band.css%>" runat="server"/>

When the page is assembled, all of the style sheets are brought together and rendered by the CssLink control.

Note Note

The CssRegistration controls may be placed on a master page, page layout, or content page.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
CssLink is required on the page
Remember that your (master)page needs the following line somewhere as it actually uses that to insert the CSS registrations into the HTML:

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<SharePoint:CssLink runat="server" Version="4"/>

The html equivallent of this code to add a CSS registration is:

<SharePoint:CssRegistration ID="SomeCssRegistration" name="<%$SPUrl:~SiteCollection/Style Library/Styles/mycss.css%>" runat="server"/>
Issue in Foundation
As you will see in http://blogs.msdn.com/b/sharepointdesigner/archive/2010/04/09/working-with-the-sharepoint-theming-engine.aspx the $SPUrl url resolve technique won't work if you are using SharePoint Foundation 2010, I'm working on a simple workaround, when done will publish it.
Correction
As in the 2007 version documentation, in the example, $SPrl:~ should be $SPUrl:~