zoukankan      html  css  js  c++  java
  • 用HtmlLink来改变网站的主题

    #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;
            }
    
  • 相关阅读:
    Redis慢查询日志
    Docker:容器
    CentOS7.X中使用yum安装nginx
    Nginx简介及配置详解(二)
    Nginx简介及配置详解(一)
    Redis持久化策略
    golang学习笔记——异常
    golang学习笔记——面向对象(接口)
    golang学习笔记——面向对象(方法)
    golang学习笔记——struct结构体
  • 原文地址:https://www.cnblogs.com/zlqblog/p/4633752.html
Copyright © 2011-2022 走看看