代码改变世界

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

2012-08-09 11:18  ATP_  阅读(702)  评论(0编辑  收藏  举报

主题十分简单。。。按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());
        }
    }
}