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

前端 未结 7 1443
没有蜡笔的小新
没有蜡笔的小新 2021-02-12 15:24

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 theme         


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-12 16:11

    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; }
    }
    

提交回复
热议问题