0

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;
                    }
                }
mattgcon
  • 4,768
  • 19
  • 69
  • 117
  • Why are you using `parent.`? In a master/content page, they're part of the same DOM. – GalacticCowboy Feb 12 '13 at 17:40
  • I think I am using parent because the pages show up in iframes within the content pages area. Without parent the javascript will not run from other pages within the content pages area. I have tried to run it without the parent. but still no positive results – mattgcon Feb 12 '13 at 17:48
  • Have you considered just adding a `window.onload` handler to execute that function every time the page is posted back? I don't know if that would work for you, but it might be easier. – James Johnson Feb 12 '13 at 17:52
  • 1
    Won't registering a script, immediately followed by going to a different page, essentially undo the effect of registering the script? You're not rendering the page you registered the script in, you're going somewhere else. And even though it's the same page, you're asking for it again, so the version of it you were building up never gets rendered. – Ann L. Feb 12 '13 at 17:57
  • @James Johnson: that is what I was thinking awhile ago, would I put that in the body tag (ie: )? – mattgcon Feb 12 '13 at 17:58
  • @Ann: the Response.Redirect(RawUrl) causes the same page to reload, it is technicallyh not redirecting to another page – mattgcon Feb 12 '13 at 17:59
  • @mattgcon True, but since you're reloading you're throwing away everything you just did and having it perform a new GET on your page. What you were previously doing (with the register) never gets rendered. – Ann L. Feb 12 '13 at 18:01
  • @Ann: LOL ok I understand what you are saying about that logic that makes perfect sense. – mattgcon Feb 12 '13 at 18:05
  • @James: where would I put the window.onload handler. Since the two parameters that are being passed come from objects wtihin the code-behind I am a little confused – mattgcon Feb 12 '13 at 18:11

1 Answers1

0

Created dynamic registered script block to handle this issue.

mattgcon
  • 4,768
  • 19
  • 69
  • 117