我的应用包含带有内容页面的母版页。 Masterpage包含javascript函数,通过动态选择和扩展节点来操作树视图。在一个实例中,我试图通过内容页面上的代码隐藏调用主页面上的javascript函数,但javascript永远不会被调用。我在javascript中放置了断点,但它们永远不会被击中。
需要发生的是,删除项目后,内容页面会重新加载,同时我需要调用javascript函数。
注意:javascript确实有效,因为整个系统中的动态构建链接确实会触发断点并运行该函数。
以下是我通过以下方式调用javascript的代码隐藏方法:
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
这是MasterPage上的javascript函数:
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;
}
}
答案 0 :(得分:0)
创建动态注册脚本块来处理此问题。