This is a migrated thread and some comments may be shown as answers.

BeforeClientContextMenu is not firing

3 Answers 73 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Xavier
Top achievements
Rank 1
Xavier asked on 30 Aug 2011, 08:19 AM
Hi,
I am using a radtreeview in my project, earlier it had a context menu ,i need to show/hide the context menu for some particular nodes.
My nodes are dynamically loading from DB.

I implementing a radtree context menu like below.

<telerik:RadTreeView ID="rtvHierarchy" runat="server"             
            OnNodeExpand="rtvhierarchy_NodeExpand" MultipleSelect="True" Skin="Vista" 
            EnableDragAndDrop="True" OnNodeDrop="hierarchy_NodeDrop" 
            AllowNodeEditing="True" 
            BeforeClientContextMenu= "ShowContext"
            OnContextMenuItemClick="rtvhierarchy_ContextMenuItemClick" 
                        OnNodeEdit="rtvhierarchy_NodeEdit" 
            Font-Names="Arial,Times New Roman,Microsoft Sans Serif" 
            Font-Size="X-Small" Height="522px">
        <ContextMenus>
                    <telerik:RadTreeViewContextMenu Skin="Outlook" ID="MainContextMenu" runat="server">
                        <Items>
                            <telerik:RadMenuItem Value="New" Text="Create New Value" runat="server"></telerik:RadMenuItem>
                            <telerik:RadMenuItem Value="Rename" Text="Rename Node" runat="server"></telerik:RadMenuItem>  
                            <telerik:RadMenuItem Value="Cut" Text="Cut" runat="server"></telerik:RadMenuItem>
                            <telerik:RadMenuItem Value="Paste" Text="Paste" runat="server"></telerik:RadMenuItem>                           
                        </Items>
                        <CollapseAnimation Duration="200" Type="OutQuint" />
                    </telerik:RadTreeViewContextMenu>                                    
         </ContextMenus>         
        </telerik:RadTreeView>

I want to enable "Create New Value" and "Rename Node" on node level and Cut and Paste is on item level, i try to implement this like below,

BeforeClientContextMenu= "ShowContext" is a event which will fire before the context menu loads.

function ShowContext(node, e) {

       

             if (node.Category == "item")

            {

                var menuItem = MainContextMenu.FindItemByText("Create New Value");

                menuItem.Disable();

                var menuItem1 = MainContextMenu.FindItemByText("Rename Node");

                menuItem1.Disable();

            }

             else

            {

                var menuItem = MainContextMenu.FindItemByText("Cut");

                menuItem.Disable();

                var menuItem1 = MainContextMenu.FindItemByText("Paste");

                menuItem1.Disable();

            }

             return false;

        }
 
 The problem is the BeforeClientContextMenu is not firing the "ShowContext" function.

Please help me.

Note: I am only refereing the teleric.web.UI dll in my project solution, i am not installed telerik it in my machine.

Regards,
Xavier
 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Aug 2011, 09:43 AM
Hello Xavier,

You can use the client event OnClientContextMenuShowing which worked as expected. Take a look at the following help documentation which explains more about this.
Migrating from RadTreeView for ASP.NET to ASP.NET AJAX

Thanks,
Princy.
0
Xavier
Top achievements
Rank 1
answered on 30 Aug 2011, 11:14 AM
Thanks Princy,

I tried OnClientContextMenuShowing , its trigering now

The problem is i want to do a search inside the context menu for enable/ disable menu items accordingly, what is the code to search that.

Regards,
Xavier
0
Plamen
Telerik team
answered on 01 Sep 2011, 08:45 AM
Hello Xavier,

You can consult with the Context menu demo, where a similar functionality is described

Hope this will help.

Greetings,
Plamen Zdravkov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
TreeView
Asked by
Xavier
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Xavier
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or