[CLOSED] Disable a MenuItem when button selected

  1. #1

    [CLOSED] Disable a MenuItem when button selected

    I have created a Button with a Menu. The menu items are added in the behind code and all of that works:

    ...
    <TopBar>
       <ext:Toolbar runat="server"
          <Items>
             <ext:Button runat="server" Icon="Database" >
                <Menu>
                   <ext:Menu ID="CfdbOptionsMenu" runat="server"
                   <%-- MenuItems dynamically create in behind code --%>
                </Menu>
             </ext:Button>
             <ext:Label ID="CfdbVersionTitle" runat="server" />
          </Items>
       </ext:Toolbar>
    </TopBar>
    ...
    Behind Code ...
    protected void Page_Load(object sender, EventArgs e)
    {
       if (!X.IsAjaxRequest)
       {
          CFVDataContext dc = new CFVDataContext;
          
          // Retrieve all available versions that can be selected.
          var q = from c in dc.CfdbVersions
                     where c.IsActive == true
                     orderby c.Order descending
                     select c;
    
          // Create the menu items
          foreach (var c in q)
          {
             Ext.Net.MenuItems item = new Ext.Net.MenuItems()
             {
                Text = c.Description,
                Icon = Icon.Database
             };
             item.addTo(CfdbOptionsMenu);
          }
       }
    }
    What I would like to do is whenever the button is selected to display the menuItems I need to iterate through the menu items and disable the item if the menuItem.Text == CfdbVersionTitle.Text. This could be done on the client side. What listener should I use and what is the best way to iterate through the menuitems. I need to do it each time the button displays the menuItems because the title might have changed since the last time the menuitems were shown.
    Last edited by Daniil; Jun 14, 2012 at 3:23 PM. Reason: [CLOSED]
  2. #2
  3. #3
    Thanks, everything worked. You may close the thread. I added the following:

    <%-- ADDED CODE --%>
    <ext:XScript runat="server">
       <script type="text/javascript">
          var disableCurrentCfdb = function(button, menu, e) {
             menu.items.each (function(item) {
                item.setDisabled(item.text == #{CfdbVersionTitle}.text);
             });
          };
       </script>
    </ext:XScript>
    ...
    <TopBar>
       <ext:Toolbar runat="server"
          <Items>
             <ext:Button runat="server" Icon="Database" >
                <Menu>
                   <ext:Menu ID="CfdbOptionsMenu" runat="server"
                   <%-- MenuItems dynamically create in behind code --%>
                </Menu>
                <%-- ADDED LISTENER --%>
                <Listeners>
                   <MenuShow Fn="disableCurrentCfdb" />
                <Listeners>
             </ext:Button>
             <ext:Label ID="CfdbVersionTitle" runat="server" />
          </Items>
       </ext:Toolbar>
    </TopBar>
    ...
    Behind Code ...
    protected void Page_Load(object sender, EventArgs e)
    {
       if (!X.IsAjaxRequest)
       {
          CFVDataContext dc = new CFVDataContext;
          
          // Retrieve all available versions that can be selected.
          var q = from c in dc.CfdbVersions
                     where c.IsActive == true
                     orderby c.Order descending
                     select c;
    
          // Create the menu items
          foreach (var c in q)
          {
             Ext.Net.MenuItems item = new Ext.Net.MenuItems()
             {
                Text = c.Description,
                Icon = Icon.Database
             };
             item.addTo(CfdbOptionsMenu);
          }
       }
    }

Similar Threads

  1. [CLOSED] Custom icon for Button / MenuItem
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 27, 2012, 3:16 PM
  2. [CLOSED] MenuPanel Get Selected MenuItem from client side (javascript)
    By logicspeak in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Nov 23, 2011, 3:15 PM
  3. Button Enable/Disable
    By Maia in forum 1.x Help
    Replies: 5
    Last Post: Jul 02, 2010, 8:03 PM
  4. Replies: 0
    Last Post: Apr 07, 2009, 8:57 AM
  5. Enable or disable the button
    By VietView in forum 1.x Help
    Replies: 4
    Last Post: Jan 09, 2009, 11:59 AM

Posting Permissions