【Asp.net从零开始】:使用主题(Theme)

本文介绍了ASP.NET中使用主题和皮肤的方法,并提供了动态更改主题的示例代码。文章详细解释了不同配置文件中主题设置的优先级顺序,以及如何在代码中实现主题的动态切换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

主题十分简单。。。按MSDN的链接演练来练练即可http://msdn.microsoft.com/zh-cn/library/bb515247#designing_the_look_and_layout_of_a_web_site

下面写几点需要注意的:

一.APP_Theme文件夹中的不同主题包括的内容有:皮肤(skin),CSS样式,图片和其他资源

 

二.Within Asp.Net, attributes and elements take precedence in the following order:(主题选择的优先顺序,主要还是依赖于生命周期来确定的)

1.Theme attributes in the @Page directive (@Page中的Theme属性)

2.<pages Theme="themeName"> elements in the <system.Web> section of a Web.config file(Web.config 中 <pages>的Theme设置)

3.Local control attributes(本地控件自身的属性设置)

4.StyleSheetTheme attributes in the @Page directive(@Page中的StyleSheetTheme属性)

5.<pages StytleSheetTheme="themeName"> in Web.config(Web.config中<pages>的StytleSheetTheme属性)

 

三.更换皮肤时需要指明 SkinID , ImageUrl

四.编程动态更改主题的示例:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        if ((string)Session["masterName"] == null)
            MasterPageFile = "~/Master1.master";
        MasterPageFile = (string)Session["masterName"];
        
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        
        
    }


    protected void submit(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedItem != null)
        {
            Session["masterName"] = DropDownList1.SelectedItem.Value.ToString();
            Response.Redirect(Request.Url.ToString());
        }
    }
}

  

 

 

 

转载于:https://www.cnblogs.com/VortexPiggy/archive/2012/08/09/2629909.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值