tags:

views:

869

answers:

3

I'd been reading up on themes in my ASP.NET book and thought that it could be a very handy solution, then I met some problems.

  • The theme picks up every single CSS file in the folder
  • If you want to use reset styles (where ordering is important) the order of imported stylesheets is not guaranteed
  • Your master page would not explicitly indicate what style is being used, only the rendered page can tell you that unless you dig into your web.config
  • Styling web controls using the theme file is... well... stupid? You can simply do this in your stylesheet. Granular control should be at the HTML level, should it not?
  • How do you specify print stylesheets without having all styles in a single stylesheet?

I'm wondering as to whether they're actually worth using at all. Is there any benefit? Are there any major sites using them?

EDIT

Just to clarify slolife's last point. If I had two stylesheets, one called print.css and one called main.css and I used ASP.NET themes, how would it know that print.css was a print stylesheet? In regular HTML you use the media type in the tag itself (i.e. <link rel= ...>) but the themes wouldn't know this, so it would just get included as a regular stylesheet.

+4  A: 

IMHO, asp.net themes are absolutely USELESS

try implementing url rewriting with an app which uses themes and see them break straight away

basically, you can achieve the same thing writing few lines of code in asp.net and multiple css folders. i am yet to come across any developer / company who has been using themes

when asp.net 2.0 was launched, there was a big hype around themes but my personal opinion is its simply not worth it :-)

Raj
How would URL re-writing cause themes to break? For example, if the theme was set in the web.config then it's global based on the master page. So the URL shouldn't matter, regardless?
Kezzer
I guess the evaluated path is wrong
Naeem Sarfraz
+5  A: 

I like using themes, but as Raj pointed out in his answer, URL rewriting can cause problems. My search for some solutions to that is what led me to your question. But I'll add my opinions in anyway.

I'll address some of your bullets from above as to why I think themes are good:

- The theme picks up every single CSS file in the folder

I guess you are looking to apply only certain stylesheet files to certain pages. Yes, themes takes the shotgun approach here, so that's a problem. But you don't have to put all stylesheets in the the theme folder. Put your specialized ones outside of it and they won't be included automatically. But I think it is nice feature to have the common/site wide ones included automagically.

- If you want to use reset styles (where ordering is important) the order of imported stylesheets is not guaranteed

I think you can guarantee the order by the way you name the files, so they are numerically and alphabetically ordered. Maybe not an elegant solution, but not horrible.

Personally, I have a build step that combines and compresses all of the *.css files in my theme folder into one single style.css file, and since I control that build step and the order that the files are combined, that doesn't affect me.

- Your master page would not explicitly indicate what style is being used, only the rendered page can tell you that unless you dig into your web.config

You can change the theme via code and in the <%@Page directive

- Styling web controls using the theme file is... well... stupid? You can simply do this in your stylesheet. Granular control should be at the HTML level, should it not?

I agree that applying style attributes to controls via the theme doesn't seem to be a best practice. But I love the fact that I can define image skins in the theme's skin files and don't have to cut and paste Width,Height,AlternativeText,Align attributes for common images that I use lots of places throughout the site. And if I ever change one of those images, I can fix the attributes in one place, rather than all over. I also can created skinned controls with a certain list of css classes applied, which seems handy to me.

- How do you specify print stylesheets without having all styles in a single stylesheet?

I have a Print.css file that starts with @media print and that defines print styles for my site. Why do you need to put them in one stylesheet?

slolife
As for the first point, what if you're using include statements in your CSS stylesheets? It would pick up every single CSS file, then it would apply the include statements, which would in turn "double" include the stylesheets (or wouldn't it be recursive?)
Kezzer
As for the last point, you can use the media type in your <link> tag to specify it's a print stylesheet. So say you had two stylesheets, main.css and print.css, if you used asp.net themes, how would it know print.css was a print stylesheet?
Kezzer
@Kezzer, both of your comments show shortcomings of Themes support. If that is the you have created your site, then Themes probably won't work for you.
slolife
A: 

Use themes to change control attributes ONLY. They were bad designed for working with css.

Eduardo