Hide Context Menu Server-side Code

3 posts, 0 answers
  1. JustinWong
    JustinWong avatar
    147 posts
    Member since:
    Mar 2007

    Posted 14 Nov 2009 Link to this post

    Hi:

    I'm wondering if there is a way to hide the context menu using server-side code.  Specifically, If a user is logged in, then when the page loads, they can right-click and see the context menu.  If the user is not logged in, then right-clicking on a node won't do anything.

    The context menu is already built at design time. I don't want to re-build the menu at runtime.

    Any help on how to ahcieve this is appreciated!

    Thanks!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Nov 2009 Link to this post

    Hi JustinWong,

    One suggestion to achieve this behaviour is setting a HiddenField value (from code) based on whether user has logged in or not and canceling the 'OnClientContextMenuShowing' event after checking the HiddenField value in order to prevent the menu to appear.

    Here is the example:
     
    <telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientContextMenuShowing="OnClientContextMenuShowing"
                    <ContextMenus> 
                        <telerik:RadTreeViewContextMenu ID="MainContextMenu" 
                            runat="server"
                            <Items> 
                               . . . 
                            </Items> 
                        </telerik:RadTreeViewContextMenu> 
                    </ContextMenus> 
                    <Nodes> 
                     . . . 
                    </Nodes> 
                </telerik:RadTreeView> 
    <script type="text/javascript"
    function OnClientContextMenuShowing(sender, args) 
        if(check) // Check whether the hiddenfield value is set from code 
        args.set_cancel(true);  // Cancel the event which prevent te menu to appear 
    </script> 
     

    Regards,
    Shinu.
  3. JustinWong
    JustinWong avatar
    147 posts
    Member since:
    Mar 2007

    Posted 18 Nov 2009 Link to this post

    Thanks Shinu. That's what I ended up doing - although I would prefer that there be methods to show/hide contextmenu on a per-node basis.

     

    Cheers!

     

    Justin

Back to Top