[CLOSED] Adding menu items to button group dynamically in a direct event..

  1. #1

    [CLOSED] Adding menu items to button group dynamically in a direct event..

    Hi,

    I'm trying to add menu items dynamically to button group, when user selects one of the item in a SelectBox. However, i do not see any menu item in the button group. Looks like, it is not getting rendered after adding items to the menu.

    Here is the sample code, which i'm calling in direct event of SelectBox:

     private void BindMenuItems()
        {
            for (int i = 0; i < 5; i++)
            {
                Ext.Net.MenuItem menuItem = new Ext.Net.MenuItem();
                menuItem.ID = "item" + i.ToString();
                menuItem.Text = "item " + i.ToString();
                this.btnMenu.Items.Add(menuItem);
            }      
            
        }
    Appreciate, if you can suggest the right way to achieve this.

    Thanks.
    Last edited by Daniil; May 21, 2012 at 9:45 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Changing Items collection during DirectEvent/DirectMethod doesn't affect on client automatically. You should render controls.

    In your case you could call the Render method for each MenuItem.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void AddItems(object sender, DirectEventArgs e)
        {
            Ext.Net.MenuItem mi1 = new Ext.Net.MenuItem("New item 1");
            Ext.Net.MenuItem mi2 = new Ext.Net.MenuItem("New item 2");
            this.Menu1.Items.Add(mi1);
            mi1.Render();
            this.Menu1.Items.Add(mi2);
            mi2.Render();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
        <ext:Button runat="server" Text="Menu">
            <Menu>
                <ext:Menu ID="Menu1" runat="server">
                    <Items>
                        <ext:MenuItem runat="server" Text="Item 1" />
                    </Items>
                </ext:Menu>
            </Menu>
        </ext:Button>
    
        <ext:Button runat="server" Text="Add items" OnDirectClick="AddItems" />
    </body>
    </html>
  3. #3
    Thanks Daniil. This solved my problem.

Similar Threads

  1. Replies: 5
    Last Post: Dec 21, 2015, 8:39 PM
  2. [CLOSED] Adding menu items with Ajax Event
    By gokcemutlu in forum 1.x Legacy Premium Help
    Replies: 13
    Last Post: Apr 21, 2011, 10:07 AM
  3. Dynamically Added Button Direct Event Does Not Work
    By rosencrantz in forum 1.x Help
    Replies: 1
    Last Post: Apr 19, 2011, 9:41 AM
  4. [CLOSED] Radio Group not submitting selection during Direct Event
    By vedagopal2004 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 07, 2011, 4:17 PM
  5. [CLOSED] Adding Item to Checkbox group by Direct Event
    By amitpareek in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: May 31, 2010, 7:17 PM

Posting Permissions