unexpected behaviour w/ RadTreeView and Node Templates

3 posts, 0 answers
  1. John Crumpton
    John Crumpton avatar
    12 posts
    Member since:
    Jul 2009

    Posted 24 May 2010 Link to this post

    I have to do everything at runtime; tree nodes vary by user. I used example code to apply node templates... works as expected.
    When I select a node (and get the postback) the templates are not applied. Then I select a node again (and get the postback), the template is applied... it just toggles back and forth. Code is below....
     
      Private Sub GetAccountProducts(ByVal AccountID As StringByVal Category As StringByRef node As Telerik.Web.UI.RadTreeNode)  
            Try 
                 
                Dim objCom As New SqlClient.SqlCommand  
                Dim objDA As New SqlClient.SqlDataAdapter  
                Dim objDT As New DataTable  
     
                objCom.Connection = objSLXCon  
                objCom.CommandText = "select ap.ACCOUNTPRODUCTID, ap.SERIALNUMBER, ap.PRODUCTNAME " & _  
                    "from accountproduct ap inner join product p on ap.productid = p.productid " & _  
                    "where ap.accountid = '" & AccountID & "' and p.family = '" & Category & "' " & _  
                    "and ap.accountproductid in (select accountproductid from ADVANTAGEVISIONACCESS where contactid = '" & Request.Cookies("UserID").Value & "')" 
                objDA.SelectCommand = objCom  
                objDA.Fill(objDT)  
     
                For Each dr As DataRow In objDT.Rows  
                    Dim AssetNode As New Telerik.Web.UI.RadTreeNode()  
                    AssetNode.Text = dr.Item("SERIALNUMBER").ToString  
                    AssetNode.Value = dr.Item("ACCOUNTPRODUCTID").ToString  
                    AssetNode.Attributes.Add("Level""Asset")  
                    AssetNode.Attributes.Add("Model", dr.Item("PRODUCTNAME"))  
                    AssetNode.NavigateUrl = "Assets.aspx?Level=Asset&AssetID=" & dr.Item("ACCOUNTPRODUCTID").ToString  
                    Dim template As New AssetTemplate()  
                    template.InstantiateIn(AssetNode)  
                    node.Nodes.Add(AssetNode)  
                Next 
     
            Catch ex As Exception  
     
            End Try 
        End Sub 
     
    Class AccountTemplate  
        Implements ITemplate  
     
        Public Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn  
            Dim label1 As New Label()  
            Dim node As RadTreeNode = DirectCast(container, RadTreeNode)  
            label1.ID = "accountnamelabel" 
            label1.Text = node.Text  
            label1.ForeColor = Drawing.Color.Black  
            container.Controls.Add(label1)  
        End Sub 
     
    End Class 
     
    Class ContactTemplate  
        Implements ITemplate  
     
        Public Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn  
            Dim label1 As New Label()  
            Dim node As RadTreeNode = DirectCast(container, RadTreeNode)  
            label1.ID = "alllocationslabel" 
            label1.Text = node.Text  
            label1.ForeColor = Drawing.Color.Black  
            container.Controls.Add(label1)  
        End Sub 
     
    End Class 
     
    Class FamilyTemplate  
        Implements ITemplate  
     
        Public Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn  
            Dim label1 As New Label()  
            Dim node As RadTreeNode = DirectCast(container, RadTreeNode)  
            label1.ID = "familynamelabel" 
            label1.Text = node.Text  
            label1.ForeColor = Drawing.Color.Black  
            container.Controls.Add(label1)  
        End Sub 
     
    End Class 
     
    Class AssetTemplate  
        Implements ITemplate  
     
        Public Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn  
            Dim label1 As New Label()  
            Dim label2 As New Label()  
     
     
            Dim node As RadTreeNode = DirectCast(container, RadTreeNode)  
            label1.ID = "assetnamelabel" 
            label1.Text = node.Attributes("Model")  
            label1.ForeColor = Drawing.Color.Black  
            container.Controls.Add(label1)  
            label2.ID = "assetseriallabel" 
            label2.Text = " - SN: " & node.Text  
            label2.ForeColor = Drawing.Color.Black  
            container.Controls.Add(label2)  
        End Sub 
     
    End Class 
  2. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 26 May 2010 Link to this post

    Hi John Crumpton,

    When do you apply the templates? Usually they should be applied on "Page_Init"-time.

    Could you please send me an example project reproducing the issue. To do that you have to open a support ticket and attach the archive with the project there.

    Your code seems to be perfectly fine, that is why I need more than just a part from the code-behind.
    My advice for you is - prepare a project as simple as possible and still reproducing the problem.

    Thanks.


    Regards,
    Nikolay Tsenkov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. John Crumpton
    John Crumpton avatar
    12 posts
    Member since:
    Jul 2009

    Posted 26 May 2010 Link to this post

    Thanks Nikolay,
    I opened a ticket w/ a sample solution that does reproduce the problem... in the process of removing the unnecesary bits (data binding, etc) from my working project, I found that the problem only occurs when I update other controls in the tree's nodeclick event. The nodeclick event does force a postback... but I'm checking for that in the init event, so the nodes/templates are not recreated. If i remove the postback check and remove/recreate the nodes, it still loses the template formatting.
Back to Top