Isn’t it always the way? Delphi-style actions in C#

There’s no doubt ASP.NET 2.0 Themes look like a compelling way of skinning your web app at first glance. Look a little deeper, though, and it seems that Themes could easily seduce you into using MS-only ASP.NET property attributes instead of thinking about your markup tree semantically and coding your CSS in a W3C and Dave Shea-approved manner. You might think that
<asp:button runat="server" ForeColor="White" BackColor="Orange"/>
looks like a nice way to ensure your buttons turn out a particular way, but this will render to style="background-color: orange; color: white;" ... on every button you generate. This gives you the bloated markup associated with ASP.NET 1.0 applications that we all hoped would be a thing of the past in 2.0.

A better approach might be to use CssClass instead, but even this is a little too simplistic as it requires a lengthy catalogue of simple .className style rules. This doesn’t make for the most readable stylesheets, and you’re still artificially inflating the size of your markup by tacking a class="className" attribute onto every tag that uses the class, completely ignoring the opportunity to style by position within the HTML tree. You could argue that this is because IE’s implementation of CSS Selectors is less complete than its more W3C-compliant peers (you’d be right, too ;) ).

So when all’s said and done, I think Themes are a way of getting around the fact that the default ASP.NET controls don’t emit markup which as a CSS designer you’d want or expect. The CheckBox is a prime example of this – it gets wrapped in a span, which means you expect to be styling one tag and end up styling another. That doesn’t mean Themes won’t be useful, it’s just that I think I’m going to have to limit my use of them. Also, to some extent I’ll still be fighting the framework to get the markup I want, at least until I’ve written a small armoury of 2.0 server controls.

Thankfully, while this is a problem with out-of-the-box ASP.NET 2.0 (and I do think you have to be very careful with how you use themes for this reason, despite the fact they’re evidently very useful tools), the mechanism has at least arrived by which you can output markup which plays nicer with CSS.

Perhaps now I’ll finally get around to fixing asp:CheckBox.

Leave a Reply

(required)

(required)

© 2014 ZephyrBlog Suffusion theme by Sayontan Sinha