How to not-show menu that displayed when right click on the node ?

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

    Posted 21 Feb 2013 Link to this post

    Menu is dinamically created in code behind:

    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"

    It creates following nodes on the page:

    Node 1
         Node2
              Node3
                   Node4

    Pointing to Node4, then clicking right mouse button displays menu with the following items :
    "Open", "Open in New Tab","Open in New Window", "Save Target As", etc.

    How to Not-show that menu on the right mouse button click on Node4 ?

    Thank you

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Feb 2013 Link to this post

    Hi Marina

    Try the following code snippet to hide the RadContextMenu for a  particular node.
    Hope this helps.
    aspx:
    <telerik:RadTreeView ID="RadTreeView" runat="server" OnClientContextMenuShowing="OnClientContextMenuShowing">
        <Nodes>
            <telerik:RadTreeNode Text="Node 1">
            </telerik:RadTreeNode>
            <telerik:RadTreeNode Text="Node 2">
            </telerik:RadTreeNode>
            <telerik:RadTreeNode Text="Node 3">
            </telerik:RadTreeNode>
            <telerik:RadTreeNode Text="Node 4">
            </telerik:RadTreeNode>
        </Nodes>
        <ContextMenus>
            <telerik:RadTreeViewContextMenu ID="RadTreeViewContextMenu1" runat="server">
                <Items>
                    <telerik:RadMenuItem  Text="Open">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Text="Open in new tab" >
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem  Text="Save Target as">
                    </telerik:RadMenuItem>
                </Items>
            </telerik:RadTreeViewContextMenu>
        </ContextMenus>
    </telerik:RadTreeView>
    JS:
    <script type="text/javascript">
    function OnClientContextMenuShowing(sender, args)
    {
      var menu = $find("<%= RadTreeViewContextMenu1.ClientID %>");
      if (args.get_node().get_text() == "Node 4")
      {
         args.set_cancel(true);
      }
    }
    </script>

    Thanks
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marina
    Marina avatar
    7 posts
    Member since:
    Apr 2012

    Posted 22 Feb 2013 Link to this post

    In my case there is no RadTreeViewContextMenu item.
    Menu that has "Open", "Open in New Tab", etc. items is the default menu that comes with RadTreeView control.
    Also all the nodes of RadTreeView are created dynamically by loading XML as I specified.
    Some more details:

    MyPage.aspx  has

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="MyPage.aspx.vb" MasterPageFile="~/MyBase.master" Inherits="MyNamespace.MyPage" %>
    <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.FindNodeByText("Node4").Text = "TEST 2466

    ‘This line does Not cancel default context menu:
    objMenu.Nodes.FindNodeByText("Node1").Nodes.FindNodeByText("Node2").Nodes.FindNodeByText("Node3").Nodes.FindNodeByText("Node4"). EnableContextMenu = False
    End Sub

    So, how to cancel dfault context menu in my case ? Thank you

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

    Posted 22 Feb 2013 Link to this post

    In my case there is no RadTreeViewContextMenu item.
    Menu that has "Open", "Open in New Tab", etc. items is the default menu that comes with RadTreeView control.
    Also all the nodes of RadTreeView are created dynamically by loading XML as I specified.
    Some more details:

    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);
            }
        }
    </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

  6. 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
UI for ASP.NET Ajax is Ready for VS 2017