Theme vs StyleSheetTheme

I wrote about using conditional comments to serve different css to IE browsers.  There is a little gotcha when using this this with ASP.NET Themes.

When applying themes by setting the "theme" property in the page directive or in web.config, the conditional comments appears before the the App_Theme code in the html source.  The effect is that this will overwrite your conditional comments due to the cascading nature of CSS and precedence.  One way to make the conditonal comments appear out after the css links from App_Theme is to use the StyleSheetTheme attribute instead of the Theme attribute.  This little talked about property will link App_Theme as the first thing in the Head tag (instead of the last).  Now your conditional css comments will take precedence over the styles in the App_theme.

You can read more about this on The Microsoft MSDN Library.

http://msdn2.microsoft.com/en-us/library/ykzx33wh....

Hope this helps.

UPDATE:  Steve Clements writes about another benefit from using StyleSheetTheme.  The StyleSheetTheme property gets applied much earlier during the page lifecycle than the Theme property.  With StyleSheetTheme, your theme will show up during design time. Steve also writes a caveat, "One thing to note is that setting EnableTheming=false doesn't stop applying the styleSheetTheme."

posted on Monday, September 11, 2006 11:26 AM by AlanL

Comments

# re: Theme vs StyleSheetTheme

Sunday, August 19, 2007 3:27 AM by Chandresh Kesri
I am getting a Warning while I Am trying to use skin file. then due to this problem i have search on net and not getting any sufficient solution.

Warning was:
"A SkinID has been specified but the page is not configured to use a page theme or stylesheet theme. This is acceptable if the theme or stylesheet theme will be set programmatically."

Please suggest me any solution.