set_cancel(true); does not cancel ClientContextMenuShowing event for Node in RadTreeView

4 posts, 0 answers
  1. Marina
    Marina avatar
    7 posts
    Member since:
    Apr 2012

    Posted 22 Feb 2013 Link to this post

    set_cancel(true); does not cancel  ClientContextMenuShowing event.
    Right click on the Node4 still shows default RadTreeView menu that has "Open", "Open in New Tab", etc
    Also all the nodes of RadTreeView are created dynamically by loading XML.
    Telerik.Web.UI.dll  version is 2010.2.713.35

    MyPage.aspx  has

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="MyPage.aspx.vb" MasterPageFile="~/MyBase.master" Inherits="MyNamespace.MyPage" %>
    <script type="text/javascript">
    function ClientContextMenuShowing(sender, eventArgs) {
            var node = eventArgs.get_node();
           
            if ((node.get_text() == "Node4")) {
                eventArgs.set_cancel(true);    // default context menu still displays
                alert("After set_cancel for " + node.get_text());  // displayed
            }
        }
    </script>
    <AjaxSettings>
       <telerik:AjaxSetting AjaxControlID="Timer1">
          <UpdatedControls>
             <telerik:AjaxUpdatedControl ControlID="menu1" />
          </UpdatedControls>
       </telerik:AjaxSetting>
    <asp:timer id="Timer1" runat="server" interval="300000">
    </asp:timer>

    MyBase.master  has
    <td width="100%" valign="top">
       <div id="Div1" style="display:none;">
          <telerik:RadTreeView ID="menu1" EnableEmbeddedSkins="false" runat="server" Width="220px" ShowLineImages="false"    style="display:inline-block; overflow: hidden">                                                   
          </telerik:RadTreeView>
       </div>
    </td>

    MyPage.aspx.vb  has
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       If Not Page.IsPostBack Then
          Timer1Tick(sender, e)
       End If
    End Sub

    Protected Sub Timer1Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
          LoadMyMenu()
    End Sub

    Private Sub LoadMyMenu()
          Dim objMenu As Telerik.Web.UI.RadTreeView = CType(m.GetMasterMenu(), Telerik.Web.UI.RadTreeView)
          Dim objUIService As New UIService(objUserSession)
          Dim objMenuData = objUIService.GetMenus(0)
          Dim XMLMenuItem = objMenuData.Item(0)
          objMenu.LoadXml(XMLMenuItem.XMLMenu.ToString)
          objMenu.Width = "220

       ‘This line works:      objMenu.Nodes.FindNodeByText("Node1").Nodes.FindNodeByText("Node2").Nodes.FindNodeByText("Node3").Nodes.FindNo   deByText("Node4").Text = "Node4”

    ‘This line does Not cancel default context menu:
    objMenu.Nodes.FindNodeByText("Node1").Nodes.FindNodeByText("Node2").Nodes.FindNodeByText("Node3").Nodes.FindNodeByText("Node4"). EnableContextMenu = False
    ‘This, together with ClientContextMenuShowing() java script function ()se above does Not cancel default context menu also:
    objMenu.OnClientContextMenuShowing = "ClientContextMenuShowing"

    End Sub

    So, how to cancel default context menu in my case for a particular node or set of nodes. Thank you

     

  2. Marina
    Marina avatar
    7 posts
    Member since:
    Apr 2012

    Posted 22 Feb 2013 Link to this post

    Also, Menu is null in the following: 

    function ClientContextMenuShowing(sender, eventArgs) {      
             
            var node = eventArgs.get_node();       
            var menu = eventArgs.get_menu();
           
            alert (menu.get_id().toString());  // Exception here because menu is null
                          
           
            if ((node.get_text() == "Node4")) {
           
                eventArgs.set_cancel(true);
                alert("After set_cancel for " + node.get_text());       
            }
        }

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Feb 2013 Link to this post

    Hi,

    I suppose you want to hide the default browser context menu. Here is the sample code.
    JS:
    function pageLoad() {
            var tree = $get("<%= RadTreeView1.ClientID %>");
           $addHandler(tree, "contextmenu", onMouseDown);
        }
        function onMouseDown(e) {
            e.preventDefault();
        }

    Thanks,
    Princy.
  5. Marina
    Marina avatar
    7 posts
    Member since:
    Apr 2012

    Posted 25 Feb 2013 Link to this post

    I think I found solution. In my case adding the below to the master page prevents default context menu to be displayed for all derived pages:

     

    in   .master

    <script type="text/javascript">

    function ClientContextMenuShowing(sender, eventArgs) {

     alert("ClientContextMenuShowing in RI");

     var node = eventArgs.get_node();

     $telerik.cancelRawEvent(eventArgs.get_domEvent());

     }

    </script>

     

    <telerik:RadTreeView ID="mnu" runat="server" Width="220px" ...... onClientContextMenuShowing="ClientContextMenuShowing">

    Hope it helps other developers

Back to Top