ASP.NET Themes - Should They Be Used?

雨燕双飞 提交于 2019-12-18 12:47:21

问题


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.


回答1:


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?




回答2:


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 :-)




回答3:


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



来源:https://stackoverflow.com/questions/689759/asp-net-themes-should-they-be-used

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!