ASP.NET Multiple Themes in One Site

末鹿安然 提交于 2020-01-04 06:27:12

问题


I have an App_Themes directory, and also Master pages for a ASP.NET website.

Can I use 2 different themes based on the master page?


回答1:


MSDN has an article about ASP.NET Master Pages And Themes

You cannot directly apply an ASP.NET theme to a master page. If you add a theme attribute to the @ Master directive, the page will raise an error when it runs.

However, themes are applied to master pages under these circumstances:

  • If a theme is defined in the content page. Master pages are resolved in the context of content pages, so the content page's theme is applied to the master page as well.

  • If the site as a whole is configured to use a theme by including a theme definition in the pages Element (ASP.NET Settings Schema) element.

In addition to the above you can see the section about Themes and Skins. You can change theme programmatically

Example from MSDN

protected void Page_PreInit(object sender, EventArgs e)
{
    switch (Request.QueryString["theme"])
    {
        case "Blue":
            Page.Theme = "BlueTheme";
            break;
        case "Pink":
            Page.Theme = "PinkTheme";
            break;
    }
}

But you cannot use two themes at the same time, that does not make any sense. You could however change the theme based on which masterpage is used.

To answer your question in your comment, yes you can have different themes for different sub-folders. This is from MSDN:

A theme setting in the Web.config file applies to all ASP.NET Web pages in that application. Theme settings in the Web.config file follow normal configuration hierarchy conventions. For example, to apply a theme to only a subset of pages, you can put the pages in a folder with their own Web.config file or create a element in the root Web.config file to specify a folder. For details, see Configuring Specific Files and Subdirectories.



来源:https://stackoverflow.com/questions/4951092/asp-net-multiple-themes-in-one-site

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!