Context menu won't display

2 posts, 0 answers
  1. Mark Brown
    Mark Brown avatar
    5 posts
    Member since:
    Oct 2008

    Posted 19 Nov 2009 Link to this post

    I have an asp.net page that has a Treeview control.  The Treeviwe control consists of "Controller" nodes and "Reader" nodes.  The reader nodes are children to the Controller nodes.  So fully expanded, my control should look somethign like this:

    ++ Root Node
        -- Controller Node
            -- Reader Node
            -- Reader Node
        -- Controller Node

    This Treeview control is built entirely from the page's code-behind.  I have several context menus based on the type of node.  The problem is that when I right-click, the context menu wil only display on the "root node".  I cannot get a context menu to display on any other node.

    I have alternately set the EnableContextMenu on the nodes without any effect.  I have included a simplified version of the source code that creates the nodes.

    So, any help would be greatly appreciated.  Here's the code:

                try 
                {  
                    tvStatus.Nodes.Clear();  
     
                    RadTreeNode Root = new RadTreeNode(Resources.Globals.MenuCommandStatus);  
                    Root.EnableContextMenu = false// I DON'T want a context menu on the root node  
     
                                    // controller menu  
                    RadTreeViewContextMenu mnuController = new RadTreeViewContextMenu();  
                    mnuController.ID = "mnuController" + DateTime.UtcNow.ToString();  
                    mnuController.SkinID = "WebBlue";  
     
                    RadMenuItem miControllerInit = new RadMenuItem(Resources.Globals.MenuInitialize);  
                    miControllerInit.SkinID = "WebBlue";  
     
                    RadMenuItem miSyncController = new RadMenuItem(Resources.Globals.MenuSyncControllerTimeMsg);  
                    miSyncController.SkinID = "WebBlue";  
     
                    mnuController.Items.Add(miControllerInit);  
                    mnuController.Items.Add(miSyncController);  
     
                    // Reader menu  
                    RadTreeViewContextMenu mnuReader = new RadTreeViewContextMenu();  
                    mnuReader.ID = "mnuReader" + DateTime.UtcNow.ToString();  
                    mnuReader.SkinID = "WebBlue";  
     
                    RadMenuItem miGrantAccess = new RadMenuItem(Resources.Globals.MenuGrantAccess);  
                    miGrantAccess.SkinID = "WebBlue";  
     
                    RadMenuItem miLockReader = new RadMenuItem(Resources.Globals.MenuLockReader);  
                    miLockReader.SkinID = "WebBlue";  
     
                    RadMenuItem miUnlockReader = new RadMenuItem(Resources.Globals.MenuUnlockReader);  
                    miUnlockReader.SkinID = "WebBlue";  
     
                    RadMenuItem miBeepReader = new RadMenuItem(Resources.Globals.MenuBeepReader);  
                    miBeepReader.SkinID = "WebBlue";  
     
                    RadMenuItem miStopAlarm = new RadMenuItem("Turn Off Alarm");  
                    miStopAlarm.SkinID = "WebBlue";  
     
                    mnuReader.Items.Add(miStopAlarm);  
                    mnuReader.Items.Add(miGrantAccess);  
                    mnuReader.Items.Add(miLockReader);  
                    mnuReader.Items.Add(miUnlockReader);  
                    mnuReader.Items.Add(miBeepReader);  
     
     
                    // controller menu  
                    RadTreeViewContextMenu mnuController = new RadTreeViewContextMenu();  
                    mnuController.ID = "mnuController" + DateTime.UtcNow.ToString();  
                    mnuController.SkinID = "WebBlue";  
     
                    RadMenuItem miControllerInit = new RadMenuItem(Resources.Globals.MenuInitialize);  
                    miControllerInit.SkinID = "WebBlue";  
     
                    RadMenuItem miSyncController = new RadMenuItem(Resources.Globals.MenuSyncControllerTimeMsg);  
                    miSyncController.SkinID = "WebBlue";  
     
                    mnuController.Items.Add(miControllerInit);  
                    mnuController.Items.Add(miSyncController);  
     
                    // Reader menu  
                    RadTreeViewContextMenu mnuReader = new RadTreeViewContextMenu();  
                    mnuReader.ID = "mnuReader" + DateTime.UtcNow.ToString();  
                    mnuReader.SkinID = "WebBlue";  
     
                    RadMenuItem miGrantAccess = new RadMenuItem(Resources.Globals.MenuGrantAccess);  
                    miGrantAccess.SkinID = "WebBlue";  
     
                    RadMenuItem miLockReader = new RadMenuItem(Resources.Globals.MenuLockReader);  
                    miLockReader.SkinID = "WebBlue";  
     
                    RadMenuItem miUnlockReader = new RadMenuItem(Resources.Globals.MenuUnlockReader);  
                    miUnlockReader.SkinID = "WebBlue";  
     
                    RadMenuItem miBeepReader = new RadMenuItem(Resources.Globals.MenuBeepReader);  
                    miBeepReader.SkinID = "WebBlue";  
     
                    RadMenuItem miStopAlarm = new RadMenuItem("Turn Off Alarm");  
                    miStopAlarm.SkinID = "WebBlue";  
     
                    mnuReader.Items.Add(miStopAlarm);  
                    mnuReader.Items.Add(miGrantAccess);  
                    mnuReader.Items.Add(miLockReader);  
                    mnuReader.Items.Add(miUnlockReader);  
                    mnuReader.Items.Add(miBeepReader);  
     
                    // add menus to treeview control                  
                    tvStatus.ContextMenus.Add(mnuController);  
                    tvStatus.ContextMenus.Add(mnuReader);  
     
     
            // get data and populate controller nodes  
                    EncAccess.AccessWS.Controller[] lstControllers = ws.Controller_GetAll(false);  
     
                    string ImageUrl = string.Empty;  
                    string ControllerName = string.Empty;  
     
                    foreach (EncAccess.AccessWS.Controller controller in lstControllers)  
                    {  
                        // get status of Controller  
                        bool bOnline = IsControllerOnline(controller);  
                          
                        if (bOnline == true)  
                        {  
                            ControllerName = controller.HostName + " (Online)";  
                            ImageUrl = "Images/flag_green.png";  
                        }  
                        else 
                        {  
                            ControllerName = controller.HostName + " (Offline)";  
                            ImageUrl = "Images/flag_yellow.png";  
                        }  
     
                        // create node for controller  
                        RadTreeNode ndController = new RadTreeNode(Resources.Globals.MenuController + " - " + ControllerName);  
                        ndController.Value = controller.ControllerID.ToString();  
                        ndController.ContextMenuID = "mnuController";  
                        ndController.EnableContextMenu = true;  
                        ndController.ImageUrl = ImageUrl;  
     
                        // get all the readers for this controller  
                        EncAccess.AccessWS.Reader[] lstReaders = ws.Reader_GetByControllerID(controller.ControllerID, false);  
     
                        RadTreeNode ndReaderRoot = new RadTreeNode(Resources.Globals.MenuReaders);  
     
                        foreach (EncAccess.AccessWS.Reader rdr in lstReaders)  
                        {  
                            EncAccess.AccessWS.ReaderStatusEnumeration status = ws.Reader_GetReaderStatus(rdr.ReaderID);  
     
                            string ReaderName = rdr.ReaderName;  
     
                            switch (status)  
                            {  
                                case EncAccess.AccessWS.ReaderStatusEnumeration.IN_ALARM:  
                                    ReaderName += " (Status = ALARM)";  
                                    ImageUrl = "Images/flag_red.png";  
                                    break;  
                                case EncAccess.AccessWS.ReaderStatusEnumeration.FORCED_DOOR_OPEN:  
                                    ReaderName += " (Status = Forced Door Open)";  
                                    ImageUrl = "Images/flag_yellow.png";  
                                    break;  
                                case EncAccess.AccessWS.ReaderStatusEnumeration.DOOR_OPEN:  
                                    ReaderName += " (Status = Door Open)";  
                                    ImageUrl = "Images/doorgroup.jpg";  
                                    break;  
                                case EncAccess.AccessWS.ReaderStatusEnumeration.DOOR_CLOSED:  
                                    ReaderName += " (Status = Door Closed)";  
                                    ImageUrl = "Images/flag_green.png";  
                                    break;  
                            }  
     
                            RadTreeNode ndReader = new RadTreeNode(ReaderName);  
     
                            ndReader.Value = rdr.ReaderID.ToString();  
                            ndReader.ContextMenuID = "mnuReader";  
                            ndReader.ImageUrl = ImageUrl;  
     
                            ndReaderRoot.Nodes.Add(ndReader);  
                        }  
     
                        ndController.Nodes.Add(ndReaderRoot);  
     
                        Root.Nodes.Add(ndController);  
                    }  
     
                    Root.Expanded = true;  
                    tvStatus.Nodes.Add(Root);  
                }  
                catch (Exception ex)  
                {  
                    throw ex;  
                }  
            }  
     


  2. Roland
    Roland avatar
    156 posts
    Member since:
    Feb 2009

    Posted 23 Nov 2009 Link to this post

    Hello,

    You menus are not showing because:

    mnuReader.ID = "mnuReader" + DateTime.UtcNow.ToString(); 

    and on your elements you are setting:

     ndReader.ContextMenuID = "mnuReader"






    The context menu Id's are different and tree cannot find them.



  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top