ASPxperienceDemos 主题外观(Themes)的实现

来源:互联网 发布:流星花园有多火 知乎 编辑:程序博客网 时间:2024/05/22 01:40

普通页面基于BasePage创建

public partial class _DefaultPage : BasePage {

}

App_Code/Utils.cs

public partial class BasePage : System.Web.UI.Page {
  protected enum DemoPageStatus { Default, New, Updated };
    public const string DefaultThemeName = "Glass";
  const int InvalidHighlightIndex = Int32.MinValue;

  …

/* Page PreInit */
    protected void Page_PreInit(object sender, EventArgs e) {
        string themeName = DefaultThemeName;

/* 从Cook获取用户主题名称 */
        if (Page.Request.Cookies[GetThemeCookieName()] != null) {
            themeName = Page.Request.Cookies[GetThemeCookieName()].Value;
        }

        string clientScriptBlock = "var DXCurrentThemeCookieName = /"" + GetThemeCookieName() + "/";";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "DXCurrentThemeCookieName", clientScriptBlock, true);

        this.Theme = themeName;
    }

  …

/* Page Load */
    protected override void OnLoad(EventArgs e) {
        base.OnLoad(e);       

        // Scripts
        RegisterScript("Utilities", "~/Scripts/Utilities.js");
        // CSS
        RegisterCSSLink("~/CSS/styles.css");
        if (!string.IsNullOrEmpty(this.cssLink))
            RegisterCSSLink(this.cssLink);
    }

  …

}

Demo.Master 模板页中的主题选择框

<dxe:ASPxComboBox AutoPostBack="True" DataSourceID="xdsThemes" Width="150px" ID="cbSkins" runat="server" EnableViewState="False" ClientInstanceName="cbSkins" OnDataBound="cbSkins_DataBound">
 <ClientSideEvents SelectedIndexChanged="function(s, e) {
    DXSaveCurrentThemeToCookies(s.GetSelectedItem().value);
    }" />
 </dxe:ASPxComboBox>

/Scripts/Utilities.js

function DXSaveCurrentThemeToCookies(name) {
    document.cookie = DXGetCurrentThemeCookieName() + "=" + name + "; expires=Thu, 13 Sep 3007 14:07:07 GMT; path=/";
}