While themes in ASP.NET 2.0 are great, one of the problems is how to have conditional stylesheets for a theme, IE6/7 specific for example; by default ASP.NET loads all stylesheets held within a theme. I've just discovered a great way to do this and it's been out there for a while, but I bet not many people have seen it. I was looking at the ASP.NET Developer Centre Design Templates and downloaded the first one, the Commerce one, which has the greatest solution to the theme/css problem.
This solution has an expression builder in it, one for themes. Expression builders are used for dynamic expressions within pages and are what is used to set connection strings. Eg:
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
Creating a theme expression builder allows us to do this:
<!-- IE7-specific fixes -->
<!--[if IE 7]>
<style type="text/css">
@import url(<asp:Literal runat="server"
Text="<%$ Themes:StylesheetTheme(~/Assets/CSS/{0}_ie7.css) %>" />);
</style>
<![endif]-->
Which gives us the aspects of conditional stylesheets, but linked to the theme. This is a really sweet idea. I just wonder how much more hidden stuff there is in the other templates at the design centre.