简体   繁体   中英

Set StyleSheetTheme in @Page directive in ASP.NET

I have a property in asp.net application

ABPS.PRR.WEB.CurrentSession.Theme

and I'm setting it in @Page directive in aspx pages like:

<%@ 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?

You could set it in the code.

Put this in the Page_PreInit method.

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.

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:

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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