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

Is there a event handler for right click event on the tree node?

3 Answers 187 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Onkar
Top achievements
Rank 1
Onkar asked on 12 Jul 2012, 02:35 PM
I have a RadTreeView on the click the nodes get selected and then at the right click a context menu is shown. This is working fine but the problem is to a context menu for a node I have to first select it and then right click on it. Is there a way by which directly on the right click the node will be selected and the context menu will appear for it.

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 12 Jul 2012, 03:35 PM
Hi,

You can handle OnClientContextMenuShowing:
<script type="text/javascript">
       function OnClientContextMenuShowing(sender, args) {
           alert(1);
       }
   </script>
   <telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientContextMenuShowing="OnClientContextMenuShowing">
       <Nodes>
           <telerik:RadTreeNode runat="server" Text="Root RadTreeNode1">
               <Nodes>
                   <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">
                   </telerik:RadTreeNode>
                   <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">
                   </telerik:RadTreeNode>
               </Nodes>
           </telerik:RadTreeNode>
           <telerik:RadTreeNode runat="server" Text="Root RadTreeNode2">
           </telerik:RadTreeNode>
       </Nodes>
   </telerik:RadTreeView>


Regards,
Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Onkar
Top achievements
Rank 1
answered on 25 Jul 2012, 08:13 PM
Hi Peter,

Thanks for your reply. I tried using the  OnClientContextMenuShowing but the problem is I need to make a call to a server side function. I have a function which handles the OnNodeClick event I need to call the same function when the right click is done. I tried using the client side method and from there trying to invoke the server side method but that was not possible. Could you suggest me a way how that can be accomplished.
0
Accepted
Peter
Telerik team
answered on 30 Jul 2012, 09:01 AM
Hi Onkar,

Please, try the following:
<script type="text/javascript">
 
       function OnClientContextMenuShowing(sender, args) {
           args.get_node().select();
           $telerik.cancelRawEvent(args.get_domEvent());
       }
 
   </script>
   <telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientContextMenuShowing="OnClientContextMenuShowing"
       OnNodeClick="RadTreeView1_NodeClick">
       <Nodes>
           <telerik:RadTreeNode runat="server" Text="Root RadTreeNode1">
               <Nodes>
                   <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">
                   </telerik:RadTreeNode>
                   <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">
                   </telerik:RadTreeNode>
               </Nodes>
           </telerik:RadTreeNode>
           <telerik:RadTreeNode runat="server" Text="Root RadTreeNode2">
           </telerik:RadTreeNode>
       </Nodes>
   </telerik:RadTreeView>

protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e)
   {
       Response.Write(e.Node.Text);
   }


Kind regards,
Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TreeView
Asked by
Onkar
Top achievements
Rank 1
Answers by
Peter
Telerik team
Onkar
Top achievements
Rank 1
Share this question
or