简体   繁体   English

在ASP.NET中的@Page指令中设置StyleSheetTheme

[英]Set StyleSheetTheme in @Page directive in ASP.NET

I have a property in asp.net application 我在asp.net应用程序中有一个属性

ABPS.PRR.WEB.CurrentSession.Theme

and I'm setting it in @Page directive in aspx pages like: 我在aspx页面的@Page指令中设置它,例如:

<%@ Page StylesheetTheme="ABPS.PRR.WEB.CurrentSession.Theme"  Title="Default" ... %>

but I'm getting runtime error 但我遇到运行时错误

Parser Error Message: Theme 'ABPS.PRR.WEB.CurrentSession.Theme' cannot be found in the application or global theme directories.

How can I implement this in page directive? 如何在page指令中实现这一点?

You could set it in the code. 您可以在代码中进行设置。

Put this in the Page_PreInit method. 将其放在Page_PreInit方法中。

Page.Theme = ABPS.PRR.WEB.CurrentSession.Theme

or 要么

Page.StyleSheetTheme = ABPS.PRR.WEB.CurrentSession.Theme

StylesheetTheme requires a theme name and you are supplying this in the wrong way. StylesheetTheme需要主题名称,而您以错误的方式提供了主题名称。

If you want to set the theme at runtime then you need to store it in a session variable, you can do it like... 如果要在运行时设置主题,则需要将其存储在会话变量中,可以像...

protected void Page_PreInit(object sender, EventArgs e)
{
    Page.StylesheetTheme = ABPS.PRR.WEB.CurrentSession.Theme;
}

If you want to set other value to the StyleSheetTheme property of a page, you'll need to override it: 如果要为页面的StyleSheetTheme属性设置其他值,则需要覆盖它:

public override string StyleSheetTheme
{
    get
    {
        return ABPS.PRR.WEB.CurrentSession.Theme;
    }
    set
    {
    }
}

But if you want to change the Theme property, just set its value in the Page_PreInit event: 但是,如果要更改Theme属性,只需在Page_PreInit事件中设置其值即可:

protected void Page_PreInit(object sender, EventArgs e)
{
    this.Theme = ABPS.PRR.WEB.CurrentSession.Theme;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM