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

Hide Context Menu Server-side Code

2 Answers 85 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
JustinWong
Top achievements
Rank 1
JustinWong asked on 14 Nov 2009, 07:44 PM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Nov 2009, 08:31 AM
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.
0
JustinWong
Top achievements
Rank 1
answered on 19 Nov 2009, 05:59 AM

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

Tags
TreeView
Asked by
JustinWong
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
JustinWong
Top achievements
Rank 1
Share this question
or