ozkank
ozkank

Reputation: 1462

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

I'm working on asp.net web project. When I run the project, It works correctly. But In server, I got the following error. How to solve this problem?

Using themed css files requires a header control on the page. (e.g. `<head runat="server" />`).
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. How to solve this problem?

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

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. <head runat="server" />).]
   System.Web.UI.PageTheme.SetStyleSheet() +2458406
   System.Web.UI.Page.OnInit(EventArgs e) +8699420
   System.Web.UI.Control.InitRecursive(Control namingContainer) +333
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,  Boolean includeStagesAfterAsyncPoint) +378

Upvotes: 20

Views: 23581

Answers (7)

Morten Holmgaard
Morten Holmgaard

Reputation: 7806

I have tried all the suggested things with out finding a solution.

I am just needing a dummy page placeholder for calling LoadControl with a UserControl. I tried setting Theme and StyleSheetTheme multiple places because System.Web.UI.Page has this OnInit method:

protected internal override void OnInit(EventArgs e) { 
    base.OnInit(e);

    if (_theme != null) { 
        _theme.SetStyleSheet();
    } 

    if (_styleSheet != null) {
        _styleSheet.SetStyleSheet();
    } 
}

I tried setting the values in OnPreInit and OnInit but that resulted in exceptions saying that I is not allowed to set those properties there. So I tried this code and found that I Theme and StyleSheetTheme where set in OnInit but not OnPreInit:

public BaseRenderingPage()
{
    EnableTheming = false;
    Theme = null;
    StyleSheetTheme = null;
}

protected override void OnPreInit(EventArgs e)
{
    if (EnableTheming || Theme != null || StyleSheetTheme != null)
        throw new Exception("OnPreInit: " + EnableTheming + ", " + Theme + ", " + StyleSheetTheme);
    base.OnPreInit(e);
}   

protected override void OnInit(EventArgs e)
{
    if (EnableTheming || Theme != null || StyleSheetTheme != null)
        throw new Exception("OnInit: " + EnableTheming + ", " + Theme + ", " + StyleSheetTheme);
    base.OnInit(e);
}

I ended solving it with this hack:

public override string Theme
{
    get { return null; }
    set { base.Theme = null; }
}

public override string StyleSheetTheme
{
    get { return null; }
    set { base.StyleSheetTheme = null; }
}

Upvotes: 0

Suvendu Shekhar Giri
Suvendu Shekhar Giri

Reputation: 1384

I feel none of the answers made above can resolve the actual issue faced by user if the page is not meant to render html. In this case, the solution is - just paste following

EnableTheming = "False" StylesheetTheme="" Theme="" 

in the @Page attribute of that page.

For example, the following source code sample:

DownloadFile.aspx.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DownloadFile.aspx.cs"
    Inherits="WebUI.Monitorization.DownloadFile"  EnableTheming="False" StylesheetTheme="" Theme=""   %>

Upvotes: 53

Muhammad Iqbal
Muhammad Iqbal

Reputation: 1

i want to extend the answer of "Suvendu Shekhar Giri". If you have many pages that does not means to render any html and just write their reponse at stream,i.e for ajax call. Place all such kind of pages into a single folder and add web.config in this folder. Add the following tag in this web.config file

pages styleSheetTheme="" theme=""

Hope this will help .

Upvotes: 0

alcor
alcor

Reputation: 658

Be sure to have just the files you need in the bin folder. If you have other dlls (old versions of actual dlls varying just by their name) strange-things-may-happen.

Upvotes: 1

gaijintendo
gaijintendo

Reputation: 423

I got this error as a result of a really bad copy and paste error in Visual Studio 2008. I'd replaced the page with some code scraps I had meant to email to a friend.

Despite killing all the contents of the aspx page, it threw no other errors.

Upvotes: 0

Michael
Michael

Reputation: 12011

For me the cause was missing the PrecompiledApp.config file on the live server since I pre-compile sites before uploading.

Upvotes: 3

Pharabus
Pharabus

Reputation: 6062

you need a head tag with runat="server" in the page (or master page) as below

<head runat="server">
    <title></title>
</head>

Upvotes: 12

Related Questions