I cannot disable RadTreeViewContextMenu dynamically in code behind

5 posts, 1 answers
  1. Betty
    Betty avatar
    3 posts
    Member since:
    Jan 2015

    Posted 05 Jan 2015 Link to this post

    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>

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 08 Jan 2015 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Betty
    Betty avatar
    3 posts
    Member since:
    Jan 2015

    Posted 09 Jan 2015 in reply to Boyan Dimitrov Link to this post

    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?
  5. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 14 Jan 2015 Link to this post

    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.

     
  6. Betty
    Betty avatar
    3 posts
    Member since:
    Jan 2015

    Posted 14 Jan 2015 in reply to Boyan Dimitrov Link to this post

    Thank you Boyan!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017