[CLOSED] How to add menu items in a DirectEvent

  1. #1

    [CLOSED] How to add menu items in a DirectEvent



    I am patterning some logic after https://examples1.ext.net/#/Toolbar/...ar_with_Menus/ and I would like to dynamically add menu items during a DirectEvent.

    In the sample, the Dynamic menu items are added at Page_Load. I would like to change the menu during the execution. How can this be done?

    I think I'd use RemoveAll() and then Add() the new items like in the example, but they don't show up on the menu.

    Thanks.

    -Steve
  2. #2

    RE: [CLOSED] How to add menu items in a DirectEvent

    Hi,

    Please see the following sample.
    Please update from SVN first. We made some changes which allows do not set ID explicitly for dynamic control (if it is not required)

    Please note that if you set DirectEvent for dynamic control then you have to rectreate that control on each request. Otherwise use DirectMethod

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
        <script runat="server">
            protected void AddMenuItem(object sender, DirectEventArgs e)
            {
                Ext.Net.MenuItem item = new Ext.Net.MenuItem("I am dynamic item");
                FirstMenu.Items.Add(item);
                
                item.Render();
            }
    
            protected void RemoveMenuItems(object sender, DirectEventArgs e)
            {
                FirstMenu.RemoveAll();
                FirstMenu.DoLayout();
            }
    
            protected void AddButtonWithMenu(object sender, DirectEventArgs e)
            {
                Ext.Net.Button b = new Ext.Net.Button();
                b.Text = "Hello";
                
                b.Menu.Add(new Ext.Net.Menu
                               {
                                   Items =
                                       {
                                           new Ext.Net.MenuItem
                                               {
                                                   Text = "Dynamic Item1"
                                               },
                                           new Ext.Net.MenuItem
                                               {
                                                   Text = "Dynamic Item2"
                                               }
                                       }
                               });
                
                Toolbar2.Items.Add(b);
                b.Render();
            }
    
        </script>
    </head>
    <body style="">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        
        <ext:Toolbar ID="Toolbar1" runat="server">
            <Items>
                <ext:Button runat="server" Text="Button with empty menu">
                    <Menu>
                        <ext:Menu ID="FirstMenu" runat="server">                        
                        </ext:Menu>
                    </Menu>
                </ext:Button>
                
                <ext:Button runat="server" Text="Add menu item">
                    <DirectEvents>
                        <Click OnEvent="AddMenuItem" />
                    </DirectEvents>
                </ext:Button>
                
                <ext:Button runat="server" Text="Remove all items">
                    <DirectEvents>
                        <Click OnEvent="RemoveMenuItems" />
                    </DirectEvents>
                </ext:Button>
            </Items>
        </ext:Toolbar>
        
        <ext:Toolbar ID="Toolbar2" runat="server">
            <Items>
                <ext:Button runat="server" Text="Add button with menu">
                    <DirectEvents>
                        <Click OnEvent="AddButtonWithMenu" />
                    </DirectEvents>
                </ext:Button>
            </Items>
        </ext:Toolbar>
    </body>
    </html>
  3. #3

    RE: [CLOSED] How to add menu items in a DirectEvent

    Recreate dynamic controls on each request or on each postback?
  4. #4

    RE: [CLOSED] How to add menu items in a DirectEvent



    Each request (including DirectEvent)
  5. #5

    RE: [CLOSED] How to add menu items in a DirectEvent



    That is exactly what I needed. Works perfectly. Thanks.

    -Steve

Similar Threads

  1. Replies: 0
    Last Post: Aug 09, 2012, 5:37 AM
  2. [CLOSED] Add items to FormPanel during a DirectEvent
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 27, 2012, 4:48 PM
  3. [CLOSED] Set MultiSelect selected items during DirectEvent
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Sep 20, 2010, 4:07 PM
  4. Replies: 11
    Last Post: Aug 30, 2010, 9:28 PM
  5. [CLOSED] [1.0] MVC sample west menu has no menu items
    By Inoventus in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Nov 24, 2009, 4:06 AM

Posting Permissions