码迷,mamicode.com
首页 > Web开发 > 详细

用HtmlLink来改变网站的主题

时间:2015-07-09 17:55:04      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

#region Theme
            // 注册样式(将主题样式至于通用样式后面) 
            HtmlLink themeCss = new HtmlLink();
            themeCss.Href = GetThemeUrl();
            themeCss.Attributes["id"] = "commonPageStyle";
            themeCss.Attributes["rel"] = "stylesheet";
            themeCss.Attributes["type"] = "text/css";
            int commonCssIndex = 0;
            bool existsCommonCss = false;

            foreach (Control control in Page.Header.Controls)
            {
                if (control is HtmlLink && (control as HtmlLink).Href.IndexOf("/css/commPage.css", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    Page.Header.Controls.AddAt(commonCssIndex + 1, themeCss);
                    existsCommonCss = true;
                    break;
                }
                commonCssIndex++;
            }
            if (!existsCommonCss)
            {
                Page.Header.Controls.AddAt(0, themeCss);
            }
            #endregion
private string GetThemeUrl()
        {
            string themeStr = "/css/themes/{0}/commPage.css?v=140917";
            switch (UserSession.getInstance().UserTheme)
            {
                case "blue":
                    themeStr = string.Format(themeStr, "blue");
                    break;
                case "purple":
                    themeStr = string.Format(themeStr, "purple");
                    break;
                case "red":
                    themeStr = string.Format(themeStr, "red");
                    break;
                case "green":
                    themeStr = string.Format(themeStr, "green");
                    break;
                default:
                    themeStr = string.Format(themeStr, "default");
                    break;
            }
            return themeStr;
        }

 

用HtmlLink来改变网站的主题

标签:

原文地址:http://www.cnblogs.com/zlqblog/p/4633752.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!