Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

ASP.NET Themes and required Head objects


:P
On this page:

Hmmm… I'm creating an RSS Feed page on one of my new apps I'm working on (yet another Blog <g>)…

 

The site uses themes but when I'm generating the Rss.aspx page which looks like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Rss.aspx.cs"

         Inherits="Westwind.WebLog.Rss"

         EnableTheming="false" EnableSessionState="false" %>

 

But ASP.NET complains about the fact that the header is missing:

 

Exception Details: System.InvalidOperationException: Using themed css files requires a header control on the page. (e.g. <head runat="server" />).

 

This even though EnableTheming is off for the page.

 

In order to get this to work I have to drop in the HTML header like this:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Rss.aspx.cs"

                       Inherits="Westwind.WebLog.Rss"

                       EnableTheming="false" EnableSessionState="false" %>

<head runat="server" id="Header" />

 

It doesn't matter for my RSS page since the XML is generated directly into the Response.OutputStream(), but this adds a little unneeded overhead into the page. But if you had a page that wanted to use the ASPX content to generate some non-HTML output that doesn't include a header you'd have to explicitly set the header visible=false I guess.


So to generate a page that shows just your text and no header:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebLog.WebForm1" %>

<head runat="server" visible=false/>This is a test

 

I guess this is not a big deal, but seems like an oversight in the page parser.

 


The Voices of Reason


 

Fredrik
March 03, 2006

# re: ASP.NET Themes and required Head objects

The fact that you're using an aspx page and hijacking the output stream is a much bigger overhead in my opinion, - I'd recommend using an http handler instead :)

Also check out the new ASP.NET 2.0 RSS toolkit, which looks really sweet: http://weblogs.asp.net/scottgu/archive/2006/02/22/438738.aspx

Mikael Söderström
March 03, 2006

# re: ASP.NET Themes and required Head objects

I had the same problem while generating RSS and images on the fly, but using ashx instead of aspx solved the problems. :)

Rick Strahl
March 03, 2006

# re: ASP.NET Themes and required Head objects

Frederik,

No doubt and normally I would a handler but the site needs to match URLs as much as possible so hence the ASPX page. Hmmm... I guess I can stuff it into my Url Rewriting handler as well.

In either case this is isn't going to matter all that much since the RSS page will cached heavily anyway.

The main point is though that EnableTheming false should really remove this header requirement.

Mark Zak
June 20, 2006

# re: ASP.NET Themes and required Head objects

You can actually get this working by setting the theme for that page to blank. ie:
<location path="CMS">
<system.web>
<pages theme="" />
</system.web>
</location>

I'm doing this in a few MCMS projects.

Rick Strahl
June 20, 2006

# re: ASP.NET Themes and required Head objects

Mark yes you can turn the theme off, but that's usually not the desired behavior in bulk. But you can also turn the theme of in the page directive with Theme="". Note that EnableTheming="false" doesn't do the trick, which is a little silly...

John R. Pattison
August 15, 2006

# re: ASP.NET Themes and required Head objects

Thanks Rick! I ran into this exact problem this morning trying to put together a quick flat-file data feed for a client. I understand what everyone else is saying -- yes there are other ways you could do it -- but I agree with you that it is an oversight in the page parser.

Alan
September 22, 2006

# re: ASP.NET Themes and required Head objects

Thanks!

Worked great... I ran into this issue using a page with an XML doctype feeding an AJAX callback...

Appreciate the help!

ernest
November 02, 2006

# re: ASP.NET Themes and required Head objects

Thanks,
the page directive Theme="" works fine for me.

# DotNetSlackers: ASP.NET Themes and required Head objects


_Guanche-
January 30, 2007

# re: ASP.NET Themes and required Head objects

Thanks much.

Doesnt make much sense to me that theme="" does the job when EnableTheming=false (which is docummented) doesnt.

Chuck
February 26, 2007

# re: ASP.NET Themes and required Head objects

Awesome! Thanks for the tip; it worked great.

Ryan Pfister
March 09, 2007

# re: ASP.NET Themes and required Head objects

I agree. Disabling theming using EnableTheming = "false" should fix the error. I came in from google searching for a solution to that exact problem (I got the "Using themed css files requires a header control on the page", then I turned disabled theming, but then still got the error).

Ken Eldridge
May 22, 2007

# re: ASP.NET Themes and required Head objects

This was the only thing that worked for me after Google'ing most of the morning. Just needed to feed by Ajax call.

luu
July 19, 2007

# re: ASP.NET Themes and required Head objects

Thanks for the tips.

Ozzie
January 23, 2008

# re: ASP.NET Themes and required Head objects

thanks for the help guys...

Mark Zak's snippet worked for me.

atx
April 02, 2008

# re: ASP.NET Themes and required Head objects

This works for me:
EnableTheming="false" StylesheetTheme=""

The hidden <head> tag is not needed then.

Victor Garcia
October 01, 2008

# re: ASP.NET Themes and required Head objects

After an hour of dealing with this... the tip worked... like a charm...
And the last one.... from atx... even better.

humbads
October 07, 2008

# re: ASP.NET Themes and required Head objects

This also works for Infragistics ImagePipe.aspx pages, that contain a SecureImagePipe control.

Axel
November 04, 2008

# re: ASP.NET Themes and required Head objects

Thanx - saved my day!

Jd
May 24, 2009

# re: ASP.NET Themes and required Head objects

So this is still a problem in 2009 with ASP.NET 3.0? Sadly, yes. 3-years later, same bug, same forum fix! Thanks! Hopefully someday Microsoft will get the message that they should fix this to save people hours of frustrations!

Eliza
February 04, 2010

# re: ASP.NET Themes and required Head objects

It was really very informative.But i would really like to add to this.
I was using Theme in my application and instead of putting in all pages , I used it through web.config file .
<pages theme="Default">
But for some of my pages the application was throwing following Exception
System.InvalidOperationException: Using themed css files requires a header control on the page. (e.g. <head runat="server" />).
at System.Web.UI.PageTheme.SetStyleSheet()
at System.Web.UI.Page.OnInit(EventArgs e)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Which means that all my pages should have runat="server" in the <head> tag, like the following:
<head runat="server"></head>

But for some pages it was difficult to use the <head> tag like the pages for not rendering 'text/html' content and as a result of which it was throwing Exception.

So here is the solution
Set EnableTheming = "False" StylesheetTheme="" Theme="" at the specific page level in the @Page attribute.
http://www.mindfiresolutions.com/

Gal
January 27, 2011

# re: ASP.NET Themes and required Head objects

This works : EnableTheming="false" Theme=""

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024