Click to Rate and Give Feedback

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
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)
Visual Basic (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
Visual Basic (Usage)
Dim instance As CssRegistration
C#
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
public sealed class CssRegistration : SPControl

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.

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

System.Object
   System.Web.UI.Control
     Microsoft.SharePoint.WebControls.SPControl
      Microsoft.SharePoint.WebControls.CssRegistration
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
CssRegistration      Content Master Ltd   |   Edit   |   Show History

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      ThreeSidedCoin   |   Edit   |   Show History

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.

Tags What's this?: Add a tag
Flag as ContentBug
correction      Marwan Tarek ... Thomas Lee   |   Edit   |   Show History
correction in the example $SPrl:~ should be $SPUrl:~
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker