dynamic RadTreeContextMenu not activating

2 posts, 1 answers
  1. Phillip
    Phillip avatar
    5 posts
    Member since:
    Jul 2012

    Posted 03 Jun 2012 Link to this post

    I have a content page that contains a RadSplitter.  On the left of the splitter is a RadPane with a Radtreeview. the treeview definition is below.

    <telerik:RadTreeView ID="rtOutline"
                            runat="server" AccessKey="w"  CausesValidation="False"
                            EnableDragAndDrop="True"  EnableDragAndDropBetweenNodes="True"
                            ExpandAnimation-Type="None" OnNodeExpand="rtOutline_NodeExpand" >
                        <telerik:RadTreeViewContextMenu ID="ElementMenu" runat="server"  EnableAutoScroll="True">
                    <ExpandAnimation Type="None" />

    As you can see I have subscribed to the Node Expand event of the server side.  There is a lot of node building code in here so I won't post it all. however a single child node is successfully created (See image nodeDetail.gif). This image shows the Id from the menu
    Protected Sub rtOutline_NodeExpand(sender As Object, e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles rtOutline.NodeExpand
        Dim newNode As RadTreeNode = NodeControl.LoadNodes(e.Node, rtOutline)
        e.Node = newNode
    End Sub

    The RadTreeContextMenu is also generated. See attachment MenuDetail.gif this image shows the detail of the menu including the fact that it has childitems.

    The process is 
    • The node is generated
    • the node id is passed into a function to generate the RadTreeContextMenu  
      and the menu is returned.
    • the menu is added to the RadTreeView
    • the menu Id is assigned to the contextrmenuid property
    • the node is then added to its parent.
    Dim nodeMenu As RadTreeViewContextMenu = myMenuBuilder.BuildMenu(targetNode)
    targetNode.ContextMenuId = nodeMenu.ID

    • the parent is returned to the controlling function and attached to the tree

    When I run this the new node shows perfectly but the menu does not.  It shows the standard IE Context menu See result.gif.

    The code for building the menu is
    Public Function BuildMenu(ByVal myNode As RadTreeNode) As RadTreeViewContextMenu
            Dim myMenu As New RadTreeViewContextMenu
            Dim menuElements As List(Of ElementWrapper) = LoadElements(myNode.Attributes("IID"))
            Dim helpItem As New RadMenuItem
            Dim iLoopCounter As Int32 = 0
            '***** Loading Menu Item
            Dim mnuLoading As New RadMenuItem
            mnuLoading.Text = "Loading..."
            mnuLoading.Enabled = False
            For Each a As ElementWrapper In menuElements
                Dim newMenuItem As New RadMenuItem
                newMenuItem.Text = a.Text
                newMenuItem.EnableImageSprite = a.Enabled
                newMenuItem.Attributes.Add("Command", a.Cmd)
                newMenuItem.Attributes.Add("CommandArg", a.CmdArg)
                newMenuItem.Attributes.Add("IID", myNode.Attributes("IID"))
                If a.Cmd = "HELP_MENU" Then
                    helpItem = newMenuItem
                    Dim aSplitter = New RadMenuItem
                    aSplitter.IsSeparator = True
                    Dim myStyle As New Style
                    myStyle.Width = Unit.Pixel(125)
                ElseIf a.Cmd = "HELP_ITEM" Then
                End If
                iLoopCounter = iLoopCounter + 1
            Dim newHeight As Int32 = iLoopCounter * 25
            If newHeight > 250 Then newHeight = 250
            myMenu.AutoScrollMinimumHeight = newHeight
            myMenu.ID = "mnu" & myNode.Attributes("IID")
            myMenu.EnableViewState = True
            myMenu.ClientIDMode = ClientIDMode.Static
            Return myMenu
        End Function

    I have tried this with and without the view state set and the ClientIDMode and still cannot get it to show,

    Questions (in order of priority)
    1. Can you please advise why the menu would not activate?
    2. Why would the menu not be maintained if the viewstate is enabled.  this happens if I click on the node after it has been generated

  2. Answer
    Plamen avatar
    2724 posts

    Posted 06 Jun 2012 Link to this post

    Hello Philip,

    I have tested a similar scenario by adding the following code to the code from this help topic:

    Protected Sub RadTreeView1_NodeExpand(sender As Object, e As RadTreeNodeEventArgs)
        Dim a As New RadTreeNode("Added Node")
    End Sub

    It worked properly and showed the dynamic created menu on the newly added node. Please elaborate a little bit how is you scenario different so we can be more helpful.

    Plamen Zdravkov
    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top