[CLOSED] Update CycleButton MenuItems in DirectEvent

  1. #1

    [CLOSED] Update CycleButton MenuItems in DirectEvent

    Hi,
    I would like to update the menuitems of a CycleButton during a directevent. This seems to work only parial, the new items are added to the menu, but the active/checked item is not set (the initial menu item is still the selected). Also the cycle functionality does not work.
    Hope you can help, thnx,
    Sander

    Ext.NET version: 2.2.0.21675
    Tested with Chrome & IE8

    <%@ Page Language="C#" %>
    
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <!DOCTYPE html>
    
    
    <script runat="server">
    
    
        public void OnTstBtnClick(object sender, DirectEventArgs e)
        {
            CycleButton1.Menu[0].RemoveAll();
    
    
            var mi = new CheckMenuItem
            {
                ID = "cmi1",
                Text = "cmi1",
                Icon = Icon.World,
            };
    
    
            CycleButton1.Menu[0].Items.Add(mi);
            mi.Render();
            
            mi = new CheckMenuItem
            {
                ID = "cmi2",
                Text = "cmi2",
                Icon = Icon.Accept,
                Checked = true
            };
    
    
            CycleButton1.Menu[0].Items.Add(mi);
            mi.Render();
    
    
            CycleButton1.Menu[0].ActiveIndex = 1;
        }
        
    </script>
    
    
    <html>
    <head id="Head1" runat="server">
        <title>CycleButton test</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:FormPanel ID="formPanel" runat="server"
                Width="400"
                Height="200"
                Title="CycleButton menu update test">
                <Items>
                    <ext:CycleButton ID="CycleButton1" runat="server" ShowText="true" PrependText="View As ">
                        <Menu>
                            <ext:Menu ID="Menu1" runat="server">
                                <Items>
                                    <ext:CheckMenuItem ID="CheckMenuItem1" runat="server" Text="Text Only" Icon="Note" />
                                    <ext:CheckMenuItem ID="CheckMenuItem2" runat="server" Text="Html" Icon="Html" Checked="true" />
                                </Items>
                            </ext:Menu>
                        </Menu>
                    </ext:CycleButton>
                </Items>
                <Buttons>
                    <ext:Button ID="tstBtn" runat="server" Text="Change menu items">
                        <DirectEvents>
                            <Click OnEvent="OnTstBtnClick" />
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>
        </form>
    </body>
    </html>
    Last edited by Baidaly; May 08, 2013 at 9:20 PM. Reason: [CLOSED]
  2. #2
    Hi Sander,

    During its life cycle (the initComponent method) a CycleButton puts its own logic on each menu item. It is not enough to render a new menu item. It needs to re-render a CycleButton itself after adding new items to its menu.
  3. #3
    Hi Daniil,
    I already tried to update the button itself (using CycleButton1.Render();), but it results in Javascript exceptions when clicking the button.
    Can you modify my example in something that works?
    Thanks!
    Sander
  4. #4
    This appears to be working.

    public void OnTstBtnClick(object sender, DirectEventArgs e)
    {
        CycleButton1.Menu[0].Items.Clear();
     
        var mi = new CheckMenuItem
        {
            ID = "cmi1",
            Text = "cmi1",
            Icon = Icon.World,
        };
        CycleButton1.Menu[0].Items.Add(mi);
             
        mi = new CheckMenuItem
        {
            ID = "cmi2",
            Text = "cmi2",
            Icon = Icon.Accept,
            Checked = true
        };
        CycleButton1.Menu[0].Items.Add(mi);
    
        CycleButton1.Render();
    }
  5. #5
    Hi Daniil, you're right, it works! Must have been doing something wrong.....
    Thanks!

Similar Threads

  1. Update Controls and Content during a DirectEvent
    By HosseinHelali in forum 1.x Help
    Replies: 1
    Last Post: Jul 12, 2011, 10:15 AM
  2. [CLOSED] Update the DirectEvent Click URL from code behind
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 15, 2011, 10:08 AM
  3. [CLOSED] How to update panel content during directevent
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Oct 06, 2010, 1:32 PM
  4. [CLOSED] Task Update DirectEvent in TaskManager
    By pil0t in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 21, 2010, 8:30 PM
  5. DirectEvent controls update strategy?
    By lukasw in forum 1.x Help
    Replies: 1
    Last Post: May 27, 2010, 12:04 PM

Tags for this Thread

Posting Permissions