in

ASP.NET Weblogs

vimodi's WebLog

What is a StyleSheetTheme?

Basically StyleSheetTheme is a Theme which gets applied in very early page cycle before the page control properties applied.

So order is like
    StyleSheetTheme -> Page -> Theme

That means control property set in StyleSheetTheme can be overridden by the control property in Page and control property set in Page can be overridden by the control property in Theme.

For example if StyleSheetTheme contain following default Label skin.
<asp:Label runat="server" Text="StyleSheetLabel" Font-Size="Small" BackColor="Red" ></asp:Label>

and Page Which has StyleSheetTheme and Theme defiened contain a Label contol as
<asp:Label runat="server" Text="PageLabel" Font-Size="X-Large" ></asp:Label>

and Theme contain following default label skin.
<asp:Label runat="server" Text="ThemedLabel" ></asp:Label>

Then the resultant Label shown will look like.
<asp:Label runat="server" Text="ThemedLabel" Font-Size="X-Large" BackColor="Red" ></asp:Label>

Above example is just to show the precedence heirarchy but generally either StyleSheetTheme or Theme will be applied to the page and not both.
StyleSheetTheme has same characteristics Theme except few differences.

  • StyleSheetTheme works in Designer
  • To apply StyleSheetTheme at Site Level define following in web.config

    <system.web>
          <pages styleSheetTheme="Theme1" />
    <system.web>

  • To apply StyleSheetTheme at Page Level

    <%@ Page Language="C#" StylesheetTheme="Theme1"%>

  • To apply StyleSheetTheme dynamically user need to override the StyleSheetTheme property.

    public override string StyleSheetTheme
    {
       get{ retrun "MyStyleSheetTheme"; }
    }

  • To apply a StyleSheetTheme to a control added dynemically user need to call ApplyStyleSheetTheme(Page) method on the control.

    Label lab1 = new Label();
    lab1.ApplyStyleSheetSkin(
    this);

  • EnableThemeing doesnt work with StyleSheetTheme. Setting EnableTheming="false" doesnt stop applying StyelSheetTheme to the page or control.
  • Can not apply SkinId dynemically.

Published May 05 2005, 12:35 AM by vimodi
Filed under:

Comments

 

TrackBack said:

May 6, 2005 4:57 PM
 

panduranga said:

Nice Article.

I have a question. Is there a way that I can apply two css files within a stylesheet and change the css based on some criteria (like based on user credentials).

Thanks,

June 20, 2008 9:31 AM
 

Anton Swanevelder said:

Hi panduranga,

You can change the theme based on some criteria by doing this:

Create more than one theme.

Then in your page_load method of your aspx page set the Page.Theme = "Theme name";

Regards,

Anton

July 9, 2008 5:39 AM
 

vivek said:

hi Anton

u never add theme in page_load.

u must be set it in page_preinit

August 20, 2008 8:34 AM

Leave a Comment

(required)  
(optional)
(required)  
Add