Question

My app consists of a Masterpage with content pages. The Masterpage contains javascript functions to manipulate a treeview by dynamically selecting and expanding nodes. In one instance I am trying to call the javascript function on the Masterpage through code-behind on a content page but the javascript never gets called. I placed break points in the javascript but they never get hit.

What needs to happen is that after the projects are deleted, the content page reloads and at the same time I need the javascript function to be called.

NOTE: the javascript does work as dynamically built links throughout the system do hit the breakpoints and the function runs.

Here is the code-behind method that I am making the call to the javascript from:

    Protected Overrides Sub OnDelete(ByVal SelectedItems As System.Collections.Specialized.NameValueCollection)
        For i As Integer = 0 To SelectedItems.AllKeys.GetLength(0) - 1
            Dim strProjectId As String = SelectedItems.AllKeys(i)
            Dim objProject As New BSProject(strProjectId)
            BSProject.Delete(Val(strProjectId), Page)
            ' log action
            BSActivity.Log(Page.User.SiteUser.intID, "Project Delete", _
                       "Project """ & objProject.strProjectName & """ of Organization """ & _
                       Projects.objOrganization.strName & """ was deleted")
    Next
    Dim script As ClientScriptManager = Page.ClientScript
    script.RegisterStartupScript(GetType(Page), "RefreshProject", "parent.refreshNodeForProjects('" & Projects.objOrganization.intID.ToString() & ":company','" & Projects.objLocation.intID.ToString() & ":location" & "');") ' "parent.refreshNodeForProjects('" & Projects.objOrganization.intID.ToString() & ":company','" & Projects.objLocation.intID.ToString() & ":location" & "');", False)
    If BSConfig.GetValue("ProjectsRefresh") = "1" Then
        Response.Redirect(Request.RawUrl)
    End If
End Sub

Here is the javascript function on the MasterPage:

                function refreshNodeForProjects(company, location) {
                    try {
                        var tree = $find("<%= radprojecttree.ClientID %>");
                        if (company != '') {
                            rootnode = tree.findNodeByValue(company);
                            rootnode.set_expanded(false);
                            rootnode.get_treeView().trackChanges();
                            rootnode.get_nodes().clear();
                            rootnode.set_expandMode(2);
                            rootnode.get_treeView().commitChanges();
                            rootnode.set_selected(true);
                            rootnode.set_expanded(true);
                            if (location != '') {
                                rootnode = GetNodebyValue(rootnode, location);
                                rootnode.set_expanded(false);
                                rootnode.get_treeView().trackChanges();
                                rootnode.get_nodes().clear();
                                rootnode.set_expandMode(2);
                                rootnode.get_treeView().commitChanges();
                                rootnode.set_selected(true);
                                rootnode.set_expanded(true);
                            }
                             scrollToNode(tree, rootnode);
                        }

                    }
                    catch (ex) {
                        throw ex;
                    }
                }
Was it helpful?

Solution

Created dynamic registered script block to handle this issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top