开发者

ASP.NET Multiple Themes in One Site

I have an App_Themes direct开发者_如何学编程ory, and also Master pages for a ASP.NET website.

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜