Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Treeview > RadTreeView in two userControls NodeClick not fired
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered RadTreeView in two userControls NodeClick not fired

Feed from this thread
  • Pako avatar

    Posted on Mar 25, 2011 (permalink)

    Hi,

    I'm trying to get RadTreeView working with user controls and it's giving me hard time.

    I've put RadTreeView control into user control, then in control Load event I register tree view into script manager to enable async postbacks. Everything works great, nodes are loading on demand (ServerSideCallback), click event gets fired as it should.

    Then I needed to put this UserControl into another UserControl, together with RadGrid and RadListView. I've handled all events as I should, including SelectedNodeChanged event, that my first user control raises when node click occurs (remember: first user control works all right). Now I'm not getting NodeClick event from TreeView. Why is that? If I remove ScriptManager registration from first user control, event gets fired, but it causes full postbacks and I need to put those controls in UpdatePanel.

    How can I achieve this? Is there any reason why single UserControl works, and UserControl inside UserControl does not raises events properly?

    Here is code of first user control (the one with tree view):

    Public Event NodeExpand As EventHandler(Of ProductTreeNodeExpandEventArgs)
     
    Public Event SelectedNodeChange As EventHandler
     
    Public ReadOnly Property SelectedNode As Integer?
        Get
            If (treeProductTree.SelectedNode Is Nothing) Then
                Return Nothing
            End If
     
            Return CInt(treeProductTree.SelectedNode.Value)
        End Get
    End Property
     
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ScriptManager.GetCurrent(Me.Page).RegisterAsyncPostBackControl(Me.treeProductTree)
    End Sub
     
    Public Sub SetBaseNodes(ByVal nodes As IEnumerable(Of BusinessLayer.Wrappers.Node))
        Dim radNodes = CreateRadTreeNodes(New List(Of BusinessLayer.Wrappers.Node)(nodes))
        For Each node As RadTreeNode In radNodes
            treeProductTree.Nodes.Add(node)
        Next
    End Sub
     
    Protected Sub ProductTree_NodeExpand(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs) _
        Handles treeProductTree.NodeExpand
        Dim nodeId As Integer = CInt(e.Node.Value)
        Dim evetArgs = New ProductTreeNodeExpandEventArgs(nodeId)
        RaiseEvent NodeExpand(Me, evetArgs)
     
        Dim results = CreateRadTreeNodes(From n In evetArgs.ChildNodes
                                         Where n.NodeParentId = nodeId
                                         Select n)
     
        For Each node As RadTreeNode In results
            e.Node.Nodes.Add(node)
        Next
    End Sub
     
    Protected Sub ProductTree_OnNodeClick(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs) _
        Handles treeProductTree.NodeClick
        RaiseEvent SelectedNodeChange(Me, New System.EventArgs())
    End Sub
     
    Protected Function CreateRadTreeNodes(ByRef treeNodes As IEnumerable(Of BusinessLayer.Wrappers.Node)) As IEnumerable(Of RadTreeNode)
        Dim resultList As List(Of RadTreeNode) = New List(Of RadTreeNode)()
     
        For Each node As BusinessLayer.Wrappers.Node In treeNodes
            Dim newNode As RadTreeNode = New RadTreeNode(node.NodeName, node.NodeId.ToString())
            newNode.PostBack = True
            If (node.ChildCount > 0) Then
                newNode.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
            Else
                newNode.ExpandMode = Nothing
            End If
            resultList.Add(newNode)
        Next
     
        Return resultList
    End Function

    Here is code of second user control:

    <asp:Panel ID="pnlCCSelector" CssClass="CCSelector" runat="server">
        <asp:Panel ID="pnlProductTree" CssClass="TreeDiv" runat="server">
            <fp:ProductTree ID="treeProductTree" runat="server" OnSelectedNodeChange="treeProductTree_SelectedNodeChange" />
        </asp:Panel>
        <asp:Panel ID="pnlCCList" CssClass="GridDiv" runat="server">
            <fp:CCGrid ID="gridCCGrid" runat="server" />
        </asp:Panel>
        <div style="clear:both;"></div>
    </asp:Panel>
    Public Sub SetBaseNodes(ByVal nodes As IEnumerable(Of BusinessLayer.Wrappers.Node))
        Me.treeProductTree.SetBaseNodes(nodes)
    End Sub
     
    Protected Sub treeProductTree_OnNodeExpand(ByVal sender As Object, ByVal e As ProductTreeNodeExpandEventArgs) _
        Handles treeProductTree.NodeExpand
        RaiseEvent NodeExpand(Me, e)
    End Sub
     
    Protected Sub treeProductTree_SelectedNodeChange(ByVal sender As Object, ByVal e As EventArgs) _
        Handles treeProductTree.SelectedNodeChange
        gridCCGrid.Rebind()
    End Sub

    Thanks in advance,

    Pako

  • Pako avatar

    Posted on Mar 25, 2011 (permalink)

    I've change code a bit, so now page is responsible of registering async postback control, and I've exposed RadTreeView control through property. On test page it all works ok, but on my real page, node click are still not firing.

    I've been able to find, that this behavior is caused by RadAjaxManager that is on page. When I remove RadAjaxManager from page, event gets fired as it should and update panel works ok. When RadAjaxManager is on page and radtreeview is registered as asnyc postback control, nodeClick is not fired.

    How can I fix this behavior? I would like to use AjaxManager on page and at the same time be able to register async controls.

  • Pako avatar

    Posted on Mar 29, 2011 (permalink)

    I've finally found out, what was causing my problems. It was ClientIDMode="Static" set on RadTreeView control.

    For some reason, which is mystery for me, RadTreeView with ClientIDMode=Static and RadAjaxManager on page (even when AjaxManager did nothing to tree view control), event for node click were not triggered. When I removed ClientIDMode from tree view definition, everything started working like it should from the begining.

    Took me some time to find what was causing all those troubles, but I hope it's finally over...

  • Maria Ilieva Maria Ilieva admin's avatar

    Posted on Mar 30, 2011 (permalink)

    Hi Pako,

    Microsoft recommends using ClientIDMode=Static only for static control. RadControls on the other hand are controls with complex hierarchies of child controls and templates so setting their ClientID mode to static will break their functionality. So for our controls we recommend using ClientIDMode "Auto" or "Predictable" in order to avoid such issues.

    Greetings,
    Maria Ilieva
    the Telerik team

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Treeview > RadTreeView in two userControls NodeClick not fired