Error when all context menus are not visible

3 posts, 0 answers
  1. Doron Yaacoby
    Doron Yaacoby avatar
    4 posts
    Member since:
    Mar 2009

    Posted 21 May 2009 Link to this post

    Hi,
    I have a page with a tree-view and two context menus that are not visible by default. When I select an item in the tree, I get a javascript error: 'Telerik.Web.UI.RadContextMenu is null or not an object'. I've fixed it for now by adding a "dummy" context-menu with no items in it (but with the Visible property set to 'true'), but I would like to know if there is a better solution.

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

    Posted 26 May 2009 Link to this post

    Hi Doron,

    I guess you want not to show the RadContextMneu for some nodes of treeview. If so, better way to accomplish this is by canceling the event in OnClientContextMenuShowing method after checking the node that the context menu is being opened for.

    ASPX:
     
    <telerik:radtreeview id="RadTreeView1" runat="server" OnClientContextMenuShowing="ClientContextMenuShowing"
    <ContextMenus> 
    <telerik:RadTreeViewContextMenu ID="ContextMenu"
        <Items> 
            <telerik:RadMenuItem Text="Copy" Value="Copy"></telerik:RadMenuItem> 
            <telerik:RadMenuItem Text="Edit" Value="Edit"></telerik:RadMenuItem> 
        </Items> 
    </telerik:RadTreeViewContextMenu> 
    </ContextMenus> 
     
    <Nodes> 
    <telerik:RadTreeNode runat="server" Text="Peripherals"
    <Nodes> 
        <telerik:RadTreeNode runat="server" Text="Printers"></telerik:RadTreeNode> 
        <telerik:RadTreeNode runat="server" Text="Scanners"></telerik:RadTreeNode> 
    </Nodes> 
    </telerik:RadTreeNode> 
    </Nodes> 
    </telerik:radtreeview> 

    JavaScript:
     
    <script type="text/javascript"
    function ClientContextMenuShowing(sender, eventArgs) 
     var node = eventArgs.get_node();    
     var menu = eventArgs.get_menu();    
     if (node.get_text() == "Printers"
      {        
          eventArgs.set_cancel(true); 
      } 
    </script> 
    Note: eventArgs.set_cancel(true) will cancel the event and the contextmenu is not shown.

    Thanks,
    Shinu.
  3. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 26 May 2009 Link to this post

    Hi Doron,

    in addition, instead of setting the Visible property to False of the context menus please use

    RadTreeView1.ContextMenus.Clear();


    Regards,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top