IStyleSheet::RegisterStyle Method
When implemented by a class, adds a new style rule to the embedded style sheet in the <head> section of a Web page.
Assembly: System.Web (in System.Web.dll)
Parameters
- style
- Type: System.Web.UI.WebControls::Style
The style rule to be added to the embedded style sheet.
- urlResolver
- Type: System.Web.UI::IUrlResolutionService
An IUrlResolutionService-implemented object that contains the context information for the current location (URL).
This method adds a new style rule and RegisteredCssClass property name to the embedded style sheet within the <head> section of a Page object, and associates the rule with an auto-generated style name. The Style object is rendered using the specified urlResolver parameter.
If urlResolver is set to nullptr, the URL of the current Page is used.
If a Style object is already registered, it is not added multiple times.
Note |
|---|
Adding or modifying styles programmatically during asynchronous postbacks is not supported. When you add AJAX capabilities to an ASP.NET Web page, asynchronous postbacks update regions of the page without updating the whole page. For more information, see Microsoft Ajax Overview. |
The following code example uses the Header implementation of IStyleSheet to demonstrate creating a custom Style object, labelStyle, and then registering it for the current location (URL). Then the label1 label calls the MergeStyle method so that the labelStyle style is applied to the label1 label.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note