Search code examples
asp.netcssapp-themes

Themes Vs. Old School Stylesheets


I have been developing websites with ASP.NET for quite a while. When I first learned how Themes and Skins work in ASP.NET, I found that it's great and easy and all.

But later on, I started to find the App_Themes approach pretty annoying, and the CSS we put in it, are not flexible at all and in any way. Am I missing something?

  1. CSS files are automatically added to aspx pages using the theme:

    I used to find this helpful back when I first started web development. But later on, when I learned more and more about CSS, I started to find this really disturbing. Sometimes, there are some pages, where it's useless to add a certain CSS file.

    And the worst part, it always adds them in alphabetical order, thus you have no control which file is first. This is important specially if you have done some sort of a "reset" CSS file. Thus naming the files can't always be what u want them to be, since you want the reset CSS file to rank at the top in the alphabetical order.

    I do realize a solution for this can be to put all the CSS code in a single file (which is actually better for a production environment). But this is pretty inflexible and will make the management of your CSS code quite hard.

  2. URL Rewriting

    This is a major issue, as the CSS files that are added to the website are of a relative path to the real aspx page, not to the URL after it has been rewritten.

    For example if this URL: http://www.example.com/date/category/item.aspx is rewritten from http://www.example.com/items.aspx?id=item. The link to the CSS file inside that page would look like this:

    <link href="App_Themes/ThemeName/style.css" type="text/css" rel="stylesheet" />

    Where it should be: <link href="../../App_Themes/ThemeName/style.css" type="text/css" rel="stylesheet" />

    Or Simply: <link href="http://www.example.com/App_Themes/ThemeName/style.css" type="text/css" rel="stylesheet" />

    Thus breaking the the webpage design, as the browsers will not find the CSS file.

These are the two major issues I have with themes. Thus what I ask, is it a bad move to ditch the App_Themes approach, and switch back to "old school" CSS design (i.e. make a normal folder, put my CSS files in it, and add the links to those CSS manually in my pages)? Is there any feature which I am missing here?


Solution

  • See MSDN for differences between two approaches - essentially, using theme, you can set any properties of controls as opposed to controlling only style. If you are using themes only for styling purposes then you will not be loosing anything going CSS way. I personally found using CSS provides far better control than using built-in themes.