[CLOSED] How to make MenuItem Clickable and call a Direct Method?

  1. #1

    [CLOSED] How to make MenuItem Clickable and call a Direct Method?

    Hi,
    I am having trouble creating the "Click Event" on a MenuItem created dynamically from an XML file. The menuItems show up correctly on the screen but when I click on the menuItem, it is giving me the error message:
    The control with ID 'id1f56fb29c2d1e820' not found

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MasterWithSusan.aspx.cs"
        Inherits="MasterPageTest.MasterWithSusan" %>
    
    <!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></title>
        <script runat="server">
            [DirectMethod]
            public string Items(Dictionary<string, string> parameters)
            {
                string tag = parameters["tag"];
    
                List<Ext.Net.MenuItem> items = new List<Ext.Net.MenuItem>();
    
                List<String> MenuList = CreateMenuItems(tag);
                foreach (string menuitem in MenuList)
                {
                    Ext.Net.MenuItem mi = new Ext.Net.MenuItem(menuitem) { Icon = Icon.ArrowRight, };
                    mi.DirectEvents.Click.Event += new ComponentDirectEvent.DirectEventHandler(mi_DirectClick);
                    items.Add(mi);
                }
               return ComponentLoader.ToConfig(items);
            }
    
            public List<String> CreateMenuItems(string masterMenu)
            {
                List<String> menuItemElements = new List<String>();
                XDocument doc = XDocument.Load(@"C:\DATA\Projects\Test\MasterPageTest\MasterPageTest\NewMenu.xml");
    
                if (doc.Root == null) return null;
                var mainMenus =
                    doc.Root.Elements("MainMenu").Where(
                        m => ((string)m.Attribute("ID") == masterMenu)).
                        Select(m => new
                        {
                            ID = (string)m.Attribute("ID"),
                            MenuName = (string)m.Attribute("MenuName"),
                            MenuItems = m.Element("MenuItems").Elements("MenuItem").Select(menuItem => (string)menuItem.Attribute("ItemName"))
                        });
                foreach (var mainMenu in mainMenus)
                {
                    menuItemElements.AddRange(mainMenu.MenuItems);
                }
    
                return menuItemElements;
    
            }
    
            public void mi_DirectClick(object o, DirectEventArgs e)
            {
                Ext.Net.X.Redirect("Test.aspx");
            }
            
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Toolbar ID="Toolbar1" runat="server">
            <Items>
                <ext:Button ID="Button1" runat="server" Text="Schedule">
                    <Menu>
                        <ext:Menu ID="Menu1" runat="server" TagString="Schedule">
                            <Items>
                                <ext:MenuItem ID="MenuItem1" runat="server" IconCls="x-loading-indicator" Text="Loading..."
                                    CanActivate="false" HideOnClick="false" />
                            </Items>
                            <Loader Mode="Component" DirectMethod="#{DirectMethods}.Items" RemoveAll="true">
                                <Params>
                                    <ext:Parameter Name="tag" Value="this.tag" Mode="Raw" />
                                </Params>
                            </Loader>
                        </ext:Menu>
                    </Menu>
                </ext:Button>
            </Items>
        </ext:Toolbar>
        </form>
    </body>
    </html>
    Below is the NewMenu.XML file:
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    
    <Menu>
    
      <MainMenu ID ="Schedule" MenuName="Schedules" Roles="Shipper" >
        <MenuItems>
          <MenuItem Id="1" ItemName="Trailer Schedule"/>
          <MenuItem Id="2" ItemName="Custom Schedule"/>
        </MenuItems>
      </MainMenu>
     
    </Menu>
    Click image for larger version. 

Name:	screenshot.PNG 
Views:	148 
Size:	24.6 KB 
ID:	5435

    Thank you in advance for your help.
    Last edited by Daniil; Jan 22, 2013 at 4:05 AM. Reason: [CLOSED]
  2. #2
    Hello!

    In your case it's better to use DirectMethod, because you have to recreate dynamic controls, in your case MenuItems, on each request.

    Some information you can read in this thread: http://forums.ext.net/showthread.php...ms-dynamically
    Last edited by Baidaly; Jan 19, 2013 at 3:38 AM.

Similar Threads

  1. Replies: 1
    Last Post: May 09, 2012, 7:08 PM
  2. MenuItem Click event is not working
    By krishna in forum 1.x Help
    Replies: 1
    Last Post: Mar 31, 2011, 5:36 AM
  3. How to get parent menuItem when click menuItem?
    By zhangsir199 in forum 1.x Help
    Replies: 2
    Last Post: Jan 21, 2011, 2:58 AM
  4. Replies: 5
    Last Post: Jan 06, 2011, 9:58 PM
  5. Dynamic Button Click Event
    By rthiney in forum 1.x Help
    Replies: 0
    Last Post: Jul 01, 2009, 6:22 PM

Tags for this Thread

Posting Permissions