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

I cannot disable RadTreeViewContextMenu dynamically in code behind

4 Answers 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Betty
Top achievements
Rank 1
Betty asked on 05 Jan 2015, 07:43 PM
Our web application has an aspx page that uses RadTreeView ( wrapper class  xcTreeView inherits RadTreeView) and RadTreeViewContextMenu for the context menus. The tree is built with all its nodes and associated context menus on each node.  The RadTreeView defines an event handler for onnodeexpand="trMenu_TreeNodePopulate".  When a user selects a node to expand, the event handler code behind determines if the node has permission to expand.  If this node is not permitted to expand, then I want to disable the right click context menus on that node. I've tried node.EnableContextMenu=false, but that doesn't seem to have any effect. What am I doing wrong? 

Here's some code snippets:

aspx.cs:
protected void trMenu_TreeNodePopulate(object sender, RadTreeNodeEventArgs e)
        {
             RadTreeNode node = e.Node;
             if (!treenav.PopulateNodefromXML(sender, node))
             {
                 e.node.EnableContextMenu = false;
             }
         }
 aspx:
<cc2:xcTreeView ID="trMenu"  runat="server" CssClass="TreeView" PersistLoadOnDemandNodes="true"
    NodeIndent="15" OnClientNodeClicking="onNodeClicking" OnClientMouseOver="ClientMouseOver"
    onnodeexpand="trMenu_TreeNodePopulate" ShowLines="True" Style="border-top-style: none;
    border-right-style: none; border-left-style: none; border-bottom-style: none;"  Skin="Outlook"   Font-Names="'Asap',Tahoma"   MultipleSelect="true"
    Width="99%" meta:resourcekey="trMenuResource1" SingleExpandPath="false" OnContextMenuItemClick="tree_ContextClicked" onClientContextMenuShown="ClientContextMenuShown" 
    OnClientContextMenuShowing="ClientContextMenuShowing">
    <ContextMenus>
        <telerik:RadTreeViewContextMenu Skin="Outlook" ID="EmptyMenu" runat="server" Width="30px"  >
            <Items>
            <telerik:RadMenuItem   IsSeparator="true"></telerik:RadMenuItem>
            </Items>
        </telerik:RadTreeViewContextMenu>
        <telerik:RadTreeViewContextMenu Skin="Outlook"  Font-Size="10pt" ID="FARMCMenu"   runat="server" Font-Names="'Asap',Tahoma">
            <Items>
            </Items>
                                                             
                <CollapseAnimation Type="None" />
        </telerik:RadTreeViewContextMenu>
            <telerik:RadTreeViewContextMenu Skin="Outlook"  Font-Size="10pt" ID="WAPCMenu" runat="server"  Font-Names="'Asap',Tahoma">
            <Items>
            </Items>
                                                            
                <CollapseAnimation Type="None" />
        </telerik:RadTreeViewContextMenu>
            <telerik:RadTreeViewContextMenu Skin="Outlook"  Font-Size="10pt" ID="SITECMenu" runat="server"  Font-Names="'Asap',Tahoma">
            <Items>
            </Items>
                                                               
                <CollapseAnimation Type="None" />
        </telerik:RadTreeViewContextMenu>
    </ContextMenus>
                                                     
</cc2:xcTreeView>

​

4 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 08 Jan 2015, 04:21 PM
Hello,

One possible reason for this behavior could be not firing the NodeExpand server-side event. The Node ExpandMode property must be set to ServerSide, ServerSideCallback or WebService for this event to fire.

I tested the provided code with the Node property Expanded="ServerSide" and it works fine.

Regards,
Boyan Dimitrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Betty
Top achievements
Rank 1
answered on 09 Jan 2015, 08:39 PM
hello Boyan, in the onnodeexpand handler (trMenu_TreeNodePopulate) which sets e.Node.EnableContextMenu=false, I checked the e.Node.ExpandMode and it is set to ServerSideCallback.  But after this, the context menu is still enabled. A right click still shows the context menu. 

I could only make it work by adding some kludgy javascript for ClientContextMenuShowing function that looks to see if the context menu is at a certain level in the tree and the node.get_nodes().get_count() is 0 (no children) and node.get_expandMode() is 0, where node is args.get_node(). In this case, I cancel the right click with args.set_cancel(true); It would have been better if setting the EnableContextMenu=false worked.  It bugs me though that I don't understand why the EnableContextMenu didn't work. Any ideas what I could be doing wrong?
0
Accepted
Boyan Dimitrov
Telerik team
answered on 14 Jan 2015, 01:30 PM
Hello,

The Node ExpandMode="ServerSideCallBack" forces firing of the NodeExpand event asyncronously from the client without postback. The NodeExpand event fires and child nodes added to the node collection are automatically transferred to the client without postback.
Since this is not a post-back the node modification to disable the context menu will not be applied.

Indeed in this specific case using the ClientContextMenuShowing is the only solution to prevent context menu from showing for the node.

Regards,
Boyan Dimitrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Betty
Top achievements
Rank 1
answered on 14 Jan 2015, 04:58 PM
Thank you Boyan!
Tags
General Discussions
Asked by
Betty
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Betty
Top achievements
Rank 1
Share this question
or