Having trouble with Listener when creating MenuItem dynamically

  1. #1

    Having trouble with Listener when creating MenuItem dynamically

    Hi,

    I am trying to create menuitems during Page_Load into a MenuPanel. The problem that I'm running into is that it seems like the listener is getting called immediately rather than simply being fired on click. Here is the code in the PostBack:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    namespace PatchUtility
    {
        public partial class MenuItem_Test : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack && !X.IsAjaxRequest)
                {
                    Ext.Net.MenuItem menuItem1 = new Ext.Net.MenuItem();
                    menuItem1.ID = "SampleTab1";
                    menuItem1.Text = "Tab #1";
                    menuItem1.AddListener("Click", "showTab('Tab 1')");
                    menuItem1.Enabled = false;
                    this.MainMenuPanel.Menu.Add(menuItem1);
    
                    Ext.Net.MenuItem menuItem2 = new Ext.Net.MenuItem();
                    menuItem2.ID = "SampleTab2";
                    menuItem2.Text = "Tab #2";
                    menuItem2.AddListener("Click", "showTab('Tab 2')");
                    menuItem2.Enabled = false;
                    this.MainMenuPanel.Menu.Add(menuItem2);
                }
            }
        }
    }
    Basically, when I first hit the page, I see the Notify messages immediately and just an error when I click on the MenuItem. I was expecting that nothing would happen during the load and when I click on the menuitem, I would see the notify messages pop up. Here is the aspx page.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MenuItem_Test.aspx.cs" Inherits="PatchUtility.MenuItem_Test" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!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 type="text/javascript">
            var showTab = function (tabName) {
                Ext.Msg.notify(tabName, "You selected tab: " + tabName);
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="MainResourceManager" runat="server"/>                                                                   
    
        <ext:Viewport ID="MainViewport" runat="server" Layout="border">
                <Items>
    
                    <ext:Panel ID="MainNavPanel" 
                        runat="server" 
                        Collapsible="true" 
                        Layout="accordion" 
                        Region="West"
                        Split="true" 
                        Title="Sample Application" 
                        Width="300">
                        <Items>
    
                            <ext:MenuPanel ID="MainMenuPanel" 
                                runat="server" 
                                Title="System Administration" 
                                Icon="FolderWrench">
                                <Menu ID="MenuAdmin" runat="server">
    
                                </Menu>
                                </ext:MenuPanel>
                        </Items>
                    </ext:Panel>
    
                    <%-- Tab section --%>
                    <ext:Panel ID="TestTabPanel1" runat="server" Region="Center" Layout="BorderLayout">
                        <Items>
                            <ext:TabPanel 
                                ID="MainTabPanel" 
                                runat="server" 
                                Border="false" 
                                Region="Center" 
                                Split="true" 
                                Collapsible="true">
    
                                <Items>
                                    <ext:Panel ID="TabTest1" runat="server" Closable="true" Title="Tab Test 1" Layout="FitLayout" CloseAction="Hide" Hidden="true">
                                        <Items>
                                            
                                        </Items>
                                    </ext:Panel>
    
                                    <ext:Panel ID="TabTest2" runat="server" Closable="true" Title="Tab Test 2" Layout="FitLayout" CloseAction="Hide" Hidden="true">
                                        <Items>
                                            
                                        </Items>
                                    </ext:Panel>
                                </Items>
    
    
                                </ext:TabPanel>
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Viewport>
        </form>
    </body>
    </html>
    If someone could point out what I'm doing wrong, that would be great. Thanks in advance for any help.

    Regards,
    Eric
  2. #2
    Hello, Eric,

    Try using the following code instead:
    menuItem1.AddListener("Click", "function () {showTab('Tab 1')}");
    I hope this helps!

Similar Threads

  1. creating shortcut dynamically
    By softlabsgroup.support in forum 1.x Help
    Replies: 0
    Last Post: Jun 06, 2012, 12:27 PM
  2. Replies: 0
    Last Post: Mar 27, 2012, 10:01 AM
  3. Replies: 0
    Last Post: Oct 27, 2011, 3:53 PM
  4. Replies: 2
    Last Post: Mar 22, 2011, 3:40 PM
  5. [CLOSED] Execute click-listener on MenuItem
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 22, 2011, 10:47 AM

Tags for this Thread

Posting Permissions