I'm playing around with themes tonight in ASP.NET 2.0. I admit it's taken me some time to arrive here primarily because I've used other ways to do my theming before.
Like so many things in ASP.NET 2.0 there's some stuff that's really nice about the implementation and what's there is easy to use and customize, but I have a hard time seeing how I can realistically use them in my apps because the implementation doesn't go quite far enough.
The way Themes work is that they basically let you assign control and CSS theming that applies formatting (ie. non code settings) which is fine. It's actually pretty powerful because you can set control properties and this can potentially cause code to run, so if you place code into a custom control and set a property that code gets run.
Theming actually works very well for this basic scenario that essentially allows you to control the display attributes of a site, so its easy to switch say a color scheme or particular control display formatting mechanism. It does this by injecting code into the page framework that automatically loads stylesheets on every page and applying the Skin settings to any controls that are either defaulting to the theme or have explicit theme/skinids set. A set of new events in the Page framework pick up the theme settings and apply them as part of the Page Lifecycle early on – prior to Init(). Nothing wrong with this and it seems to work really well…
I added theming to a small existing application I'm working on and it literally took only a few minutes to set up a couple of simple themes and have the handful of pages running with the themes. Nice.
Unless I'm missing something, this is pretty much all that it does <g>. Yeah, yeah, so I'm the demanding type, but I expected a little more than that.
So is this realistic? Sure for simple apps it might be nice to change colors images and other display attributes, but it's not what I would consider a themed site necessarily. A themed site can take a different layout with the UI moved around content or different components moved to different parts of the page. It seems odd that there is no support to set up one or more MasterPages that can be part of a Theme for example.
I realize this is not what ASP.NET 2.0 is trying to accomplish (unless I missed this in my reading and experimenting tonight), but doesn't that strike anybody else as a totally common scenario? Color and style theming is nice but really most of that can be accomplished with CSS and what Themes offers beyond that is really not that critical.
It sure would have been nice if Themes would have been designed to act as an overlay ontop of the main application folder. So you'd have a theme directory and you place files into it. When the App runs, ASP.NET could then virtualize the Themes folders with the selected theme ontop of the application directory, so anything in the themes folder would be accessible with the same directory structure as the main app.
So now you could design your app as a main application in the root, then go off create custom themes and copy them into Themes folders and have them overlaid onto your app with the themed folder taking precedence if active.
Of course, I'm only dreaming out loud here. I can see where this would be difficult to implement because once you add master pages or aspx/ascx pages (which is really what would be required to make this work), you'd have code in the Theme folder, which would need to be compiled somehow. If you have overlaid files you'd probably end up with files with the same file and classnames and that's a big problem to solve.
But maybe there was some way to expose special 'template' pages that are runtime loadable in a similar way that the Skin file is loaded and applied at runtime.
That would have been extremely useful and probably not all that difficult to do given that ASP.NET shadow copies files around anyway.
As it stands I don't really see how I can utilize Themes in my apps in a meaningful way…
Other Posts you might also like