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

Namespace: Microsoft.SharePoint.WebControls
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

'Usage

Dim instance As CssRegistration


'Declaration

<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CssRegistration
    Inherits SPControl
Remarks

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

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

NoteNote:

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

Example

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

Inheritance Hierarchy

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Community Content

CssRegistration
Added by:Content Master Ltd

Description

The CssRegistration class registers a cascading style sheet (CSS) file with a page by adding a HTML LINK element to the output HTML for that page. The browser that renders the page then applies any styles defined in the CSS file to that page. You can use the CssRegistration class declaratively or programmatically. To use the class declaratively you add markup to the ASP .NET page markup. Alternatively, you can use the class programmatically by using the methods exposed by the class in C# or Visual Basic .NET.

Usage Scenarios

You will typically use this class to register additional CSS files with a page. Registering the CSS file with the page will ensure that any controls that you have configured to use styles defined in your style sheet use the correct styles.

The following code samples show how to register a CSS file named CustomCss.css with your page.

ASP .NET Markup Sample

<SharePoint:CSSRegistration name=”CustomCss.css” runat=”server” />

C# Code Sample

CssRegistration.Register(“CustomCss.css”);

Visual Basic .NET Code Sample

CssRegistration.Register(“CustomCss.css”)
CssRegistration.Register
Added by:ThreeSidedCoin

It seems if you are to use CssRegistration.Register with two different URLs:

C#

CssRegistration.Register(@"/Style Library/WebParts/PeopleDetails/style.css");
CssRegistration.Register(@"/Style Library/WebParts/OtherWebPart/style.css");

...only the first one will register on the page. It seems as though the register method code extracts the leaf filename from the url (style.css) to check for duplicate registrations, rather than using the whole Url.

correction
Added by:Thomas Lee
correction in the example $SPrl:~ should be $SPUrl:~
© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View