views:

2542

answers:

5

I have an ASP.NET MVC (Beta 1) website that I'm using themes with. When I start my site (I'm still running using the ASP.Net Development Web Server) the default page gives me this error:


Server Error in '/' Application. Using themed css files requires a header control on the page. (e.g. ). Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Using themed css files requires a header control on the page. (e.g. ).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Using themed css files requires a header control on the page. (e.g. ).] System.Web.UI.PageTheme.SetStyleSheet() +2458366 System.Web.UI.Page.OnInit(EventArgs e) +8694828 System.Web.UI.Control.InitRecursive(Control namingContainer) +333 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378

Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053


Do I need to change something with my routes? Or do I need to do something else to my site?

Thanks.

.michael delorenzo

+2  A: 

The error is telling you that your ASP.NET page (or master page) needs to have a <head runat="server"> tag. Without it, you cannot use themes.

Since server side header tags shouldn't have a dependency on viewstate (as they are not contained in forms), it might still work.

Having said that, themes don't necessarily sit well in the MVC paradigm so you should consider whether you really need them.

Richard Szalay
A: 

If I remove themes, what you recommend that would fit in the MVC paradigm?

michaeldelorenzo
+3  A: 

A cleaner idea is to just have a "theme" consisting of CSS. In your master page (or individual views) link to the appropriate CSS files.

For example, I keep my "themes" in a theme directory under the Content directory of the site root. Each theme lives in its own folder, and has a main.css. The main.css is responsible for referencing all the other required CSS. So the master page in my example just links to the one main.css. You can even set the ViewData["theme"] variable (if you wanted) to the theme name, so the Master page could simply use that as a place holder for the correct theme directory.

Jason Whitehorn
A: 

I like your idea Jason, thanks for the tip. That would actually be very easy for me to implement. :)

Just as an fyi for anyone trying to do what I am/was doing with the Themes, I simply added the header element to the default.aspx page, and all was taken care of - just what Richard suggested.

michaeldelorenzo
You might want to give Richard or Jason the credit for Answering your question, then. It helps their SO karma.
John Dunagan
+1  A: 

This was my solution http://frugalcoder.us/post/2008/11/ASPNet-MVC-Theming.aspx just posted about this today...