[CLOSED] How to change themes in code behind.

  1. #1

    [CLOSED] How to change themes in code behind.

    Hi

    I'm new to ExtJS and Ext.Net and one of the first things I am trying to learn is how to switch to another theme.

    This is the code I am trying to use:

    <ext:ComboBox ID="cbStyleSwitcher" runat="server" SelectedIndex="0">
        <Items>
            <ext:ListItem Text="Blue Theme" Value="Default" />
            <ext:ListItem Text="Gray Theme" Value="Gray" />
            <ext:ListItem Text="Accessibility Theme" Value="Access" />
        </Items>
        <DirectEvents>
            <Select OnEvent="changeStyle" />
        </DirectEvents>
    </ext:ComboBox>
    and in codebehind

    protected void changeStyle(object sender, DirectEventArgs e)
    {
        string cSelectedTheme = "";
        cSelectedTheme = cbStyleSwitcher.SelectedItem.Value;
        if (cSelectedTheme == "Gray") ResourceManager1.Theme = Ext.Net.Theme.Gray;
        if (cSelectedTheme == "Access") ResourceManager1.Theme = Ext.Net.Theme.Access;
        if (cSelectedTheme == "Default") ResourceManager1.Theme = Ext.Net.Theme.Default;
    }   // eof -- changeStyle
    This code excutes without an error, but no change to the webform. How to i get the page to refresh and display the new theme ?


    thanks

    George
    Last edited by Baidaly; Jan 29, 2013 at 11:13 PM. Reason: [CLOSED]
  2. #2
    Hello!

    Welcome to our forum!

    Please, use the CODE tag: http://forums.ext.net/showthread.php...ing-New-Topics

    According your problem. Take a look at the following example:

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
                cbStyleSwitcher.SelectedItems.Add(new Ext.Net.ListItem(this.Session["Ext.Net.Theme"]));
        }
    
        protected void changeStyle(object sender, DirectEventArgs e)
        {
            string cSelectedTheme = cbStyleSwitcher.SelectedItem.Value;
            var theme = (Theme)Enum.Parse(typeof(Theme), cSelectedTheme);
            this.Session["Ext.Net.Theme"] = theme;
            ResourceManager1.SetTheme(theme);
        }
    </script>
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <form runat="server">
            <ext:ComboBox ID="cbStyleSwitcher" runat="server">
                <Items>
                    <ext:ListItem Text="Blue Theme" Value="Default" />
                    <ext:ListItem Text="Gray Theme" Value="Gray" />
                    <ext:ListItem Text="Accessibility Theme" Value="Access" />
                </Items>
                <DirectEvents>
                    <Select OnEvent="changeStyle" />
                </DirectEvents>
            </ext:ComboBox>
        </form>
    </body>
    </html>
  3. #3

    Thank you

    Thank you

    Works great!

    George
  4. #4
    Hi everybody,

    Please note that a doLayout call can be required after changing a Theme.

    For example, open:
    https://examples2.ext.net/

    Change Theme to Access.

    You can see how the Home tab looks.

    Running this code in the console helps.
    Ext.ComponentQuery.query("viewport")[0].doLayout()
    P.S. We will apply it soon for our Examples Explorers.
  5. #5

    Double Click Grid

    Test Posting
    Last edited by redi; Apr 03, 2014 at 4:09 AM.

Similar Threads

  1. [CLOSED] How to change a parameter store from code behind.
    By feanor91 in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Oct 12, 2012, 11:56 AM
  2. [CLOSED] How to change text of a label from code behind
    By feanor91 in forum 2.x Legacy Premium Help
    Replies: 20
    Last Post: Oct 05, 2012, 7:28 AM
  3. Change the Text value from code behind
    By marcelodecon in forum 1.x Help
    Replies: 2
    Last Post: Aug 05, 2010, 12:10 PM
  4. How to change the sikn with code-behind?
    By GaoYang in forum 1.x Help
    Replies: 1
    Last Post: Dec 29, 2008, 9:49 PM
  5. [CLOSED] Change Themes Dynamically
    By Zarzand in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 28, 2008, 6:13 PM

Tags for this Thread

Posting Permissions