Tree Node Children not refreshing on deletion of a node

4 posts, 0 answers
  1. Hunter
    Hunter avatar
    26 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2013 Link to this post

    When I delete a node using the context menu the node doesn't disappear after I rebuild the list of nodes that should be displayed.

    In my RadTree I have reports on the 3rd level.  I have a context menu that allows me to delete the report at that node.   The context menu handler displays a prompt (using RadConfirm).   When OK is selected from the prompt, I execute __doPostBack on an asp button.  The handler for that button is where the deletion of the report happens (and it does delete it from the database just fine) and then it calls the subroutine that rebuilds the list of reports at that level and then tries to redisplay that on the tree.  However the node with the deleted report continues to be displayed.

    And in my RadAjaxManager I think I have everything covered: the tree will update the tree and the button updaqtes the tree too.

    Any help on this is greatly appreciated.  Here are the relevant pieces of code:

    Here is the relevant part of the context menu handler:

     

    Protected Sub rtvReports_ContextMenuItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeViewContextMenuEventArgs)
     
        Select Case e.Node.Level
            Case 1
                 'Not important to example
            Case 2
                 
                Dim ReportType As String = e.Node.ParentNode.Text
                Dim ReportName As String = e.Node.Text
                Dim Logid As String = e.Node.Value
                Dim ClientID As String = Session("ClientID")
                Select Case e.MenuItem.Value
                     Case "Delete"
                        Session("CurrentReportTreeNode") = e.Node.ParentNode
                        lbDeleteReportType.Text = e.Node.ParentNode.Text
                        lbDeleteReportName.Text = e.Node.Text
                        lbDeleteLogID.Text = e.Node.Value
                         
                        RadWindowManager1.RadConfirm("Delete Report: " & lbDeleteReportName.Text, "DeleteReportcallback", 300, 100, Nothing, "Delete Report Confirmation")
     
                        Exit Select
     
                End Select
        End Select
     
    End Sub

    Here is the client side function DeleteReportCallBack which seems to work fine:

    function DeleteReportcallback(arg) {
        if (arg == true) {
            __doPostBack("ctl00$ContentPlaceHolder1$btnDelete", "");
        }
    }

    Here is the asp button:

    <asp:button id="btnDelete" runat="server" Text="" height=0 width="0" style="background-color:white; border-color:White; border-width:0" OnCLick="btnDelete_Click" />

    Here is the button handler and the subroutine that rebuilds the nodes at that level:

    Protected Sub btnDelete_Click()
        Dim ReportType As String = lbDeleteReportType.Text       
        Dim ReportName As String = lbDeleteReportName.Text
        Dim LogID As String = lbDeleteLogID.Text
        DeleteReport(LogID, ReportName, ReportType)
         
        Dim CurrentNode As RadTreeNode = Session("CurrentReportTreeNode")
        LoadReports(CurrentNode)
     
    End Sub
     
     
    Sub LoadReports(curnode As RadTreeNode)
        Dim ReportType As String = curnode.Text
        Dim ReportTypeParent As String = curnode.ParentNode.Text
        Dim CLientID As String = Session("ClientID")
        Dim dt As New DataTable
         
        If curnode.Nodes.Count > 0 Then
            For I As Integer = curnode.Nodes.Count - 1 To 0 Step -1
                curnode.Nodes(I).Remove()
            Next
        End If
     
        dt = BindChartNames(ReportType, CLientID) 'Gets the relevant reports from the database
         
        If dt IsNot Nothing And dt.Rows.Count > 0 Then
            dt.DefaultView.Sort = "ReportName ASC"
            For Each row As DataRow In dt.Rows
                Dim node As New RadTreeNode()
                node.Text = row("ReportName").ToString()
                node.Value = row("LogID").ToString()
                node.ContextMenuID = "ReportMenu"
     
                node.HoveredCssClass = "TreeHover"
                curnode.Nodes.Add(node)
            Next
            curnode.Expanded = True
            curnode.ExpandMode = TreeNodeExpandMode.ClientSide
        End If
    End Sub

    And here is the ajax manager and the tree definition (minus some context menus not pertinent to my question):

    <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" >
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="rtvReports">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rtvReports" LoadingPanelID="RadAjaxLoadingPanel1" />
                    <telerik:AjaxUpdatedControl ControlID="pnlDetails"  />
                    <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" />
                    <telerik:AjaxUpdatedControl ControlID="RadTabStrip1" />
                    <telerik:AjaxUpdatedControl ControlID="pnlReportType" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="btnOverwrite" >
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rtvReports" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
     
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" Skin="Office2010Black" InitialDelayTime="400" />
     
                <telerik:RadTreeView ID="rtvReports" runat="server" OnNodeExpand="rtvReports_NodeExpand"
                    OnContextMenuItemClick="rtvReports_ContextMenuItemClick" 
                    Skin="Office2010Silver" OnNodeClick="rtvReports_NodeClick"
                    OnPreRender="rtvReports_PreRender">
                     
                    <ContextMenus>
                        <telerik:RadTreeViewContextMenu runat="server" ID="ReportMenu" ClickToOpen="True">
                            <Items>
                                <telerik:RadMenuItem Text="Edit" Value="Edit">
                                </telerik:RadMenuItem>
                                <telerik:RadMenuItem Text="Run" Value="Run">
                                </telerik:RadMenuItem>
                                <telerik:RadMenuItem Text="Schedule" Value="Schedule">
                                </telerik:RadMenuItem>
                                <telerik:RadMenuItem Text="Delete" Value="Delete">
                                </telerik:RadMenuItem>
                            </Items>
                        </telerik:RadTreeViewContextMenu>
     
     
     
                    </ContextMenus>
                </telerik:RadTreeView>

    One further note on this issue:  I have a Refresh function on the parent node to the reports in the context menu.  And after I delete a report node and the node is still there, I run the refresh command from the parent node and it calls the same LoadReports subroutine and it works fine.

    Thanks for any help on this.

    LoadReports

  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 16 Aug 2013 Link to this post

    Hi Hunter,

    How do you delete this node? Please paste the code of the DeleteReport() method. What happens when  rebind the parent of the deleted node?

    Just for test try to disable Ajax by setting EnableAJAX property to false:
    <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" EnableAJAX="false">
    ...
    and try to delete any node. Are there any java script or server errors?

    Regards,
    Hristo Valyavicharski
    Telerik
    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 the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Hunter
    Hunter avatar
    26 posts
    Member since:
    Aug 2012

    Posted 20 Aug 2013 Link to this post

    Thanks for the response. 

    Here is the code that deletes the report:

    Sub DeleteReport(LogID As Integer, ReportName As String, ReportType As String)
    Dim oReportType As clsReportType = New clsReportType(ReportType)
    If oReportType IsNot Nothing Then
    Dim mySQL As String = "DELETE FROM " & oReportType.ReportTable & " WHERE " & oReportType.ReportTypeIDName & " = " & LogID
    Dim myConn As SqlConnection = New SqlConnection(AppSettings.Get("connAccess2"))
    Dim myCmd As SqlCommand = New SqlCommand(mySQL, myConn)
    myConn.Open()
    Try
    myCmd.ExecuteNonQuery()
    If oReportType.FilterTable <> "" Then
    mySQL = " DELETE FROM " & oReportType.FilterTable & " WHERE " & oReportType.ReportTypeIDName & " = " & LogID
    myCmd.CommandText = mySQL
    myCmd.ExecuteNonQuery()
    End If
    mySQL = " DELETE FROM EmailSchedule WHERE ReportName='" & ReportName & "' AND ClientiD='" & Session("ClientID") & "' "
    myCmd.CommandText = mySQL
    myCmd.ExecuteNonQuery()
    Catch ex As Exception
    ErrorHandler("DeleteReport", ex.message)
    End Try
    myConn.Close()
    End If
    End Sub

    No java errors or server errors.  I did try setting enablajax="False" without seeing any errors.

    Thansk,
    Hunter

  5. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 26 Aug 2013 Link to this post

    Hi Hunter,

    As far as I can see from this code snippet you are removing the node only from database. In order to refresh the tree with the new data you will have to populate it with the new data. Please make sure that you call rtvReports.DataBind() after removing the db record.

    Regards,
    Hristo Valyavicharski
    Telerik
    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 the blog feed now.
Back to Top