vb.net 关闭模态对话框窗口后 ASP.NET 刷新父页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14504934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET Refresh Parent Page after Closing Modal Dialog Window
提问by MF Luder
I have an ASP.NET page that launches a modal dialog window:
我有一个启动模式对话框窗口的 ASP.NET 页面:
Dim sURL As String = System.Configuration.ConfigurationManager.AppSettings("PAYORS_Path") & "PayorCopy.aspx"
lnkCopy.Attributes.Add("onclick", "javascript:window.showModalDialog('" & sURL & "',null,'status:no;dialogWidth:375px;dialogHeight:550px;dialogHide:true;help:no;scroll:yes;center:yes');return false;")
The user can create new items in this modal window. When the user clicks the Close button the modal dialog window is successfully closed, but the new items created do not appear on the parent page. When the modal window is closed I would like the parent page to refresh to show the new items the user created. Currently:
用户可以在此模式窗口中创建新项目。当用户单击关闭按钮时,模式对话框窗口成功关闭,但创建的新项目不会出现在父页面上。当模式窗口关闭时,我希望父页面刷新以显示用户创建的新项目。目前:
Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnClose.Click
Dim strjscript As String = "<script language='javascript'>self.close();</script>"
LtClose.Text = strjscript
End Sub
I have tried adding to this script:
我曾尝试添加到这个脚本:
window.opener.location.reload(true);
But then when I test I get an error that says "Unable to get value of the property 'location': object is null or undefined."
但是当我测试时,我收到一条错误消息,指出“无法获取属性‘位置’的值:对象为空或未定义。”
Any help would be much appreciated!
任何帮助将非常感激!
采纳答案by Androiderson
Instead of using the old modal dialog window, try jQuery Dialogbecause it behaves just like a modal but keeps you in the same window. Therefore it's is easily refreshed with the following code:
不要使用旧的模态对话框窗口,而是尝试使用jQuery Dialog,因为它的行为就像模态一样,但让您保持在同一个窗口中。因此,它很容易使用以下代码刷新:
location.reload(true);
For more information, check out thisquestion here at SO.
有关更多信息,请在 SO 上查看此问题。
Hope it helps.
希望能帮助到你。
回答by Damyan Petev
That would be because there is no 'opener' :) Location is method of the window object so you can even treat it as global is most cases. Any of those should work:
那是因为没有 'opener' :) Location 是 window 对象的方法,因此在大多数情况下您甚至可以将其视为全局。其中任何一个都应该有效:
window.location.reload(true);
or:
或者:
location.reload(true);
EDITYeah I just noticed where you put that script.. if it's in the click handle inside the modal..then 'window' there is really a different one - it's modal after all! Try adding it directlyafter the code opening modal window - the script execution will be blocked until the modal returns, so you can so something like this:
编辑是的,我只是注意到你把那个脚本放在哪里了..如果它在模态内的点击句柄中..那么“窗口”真的有一个不同的 - 毕竟它是模态的!尝试在代码打开模态窗口之后直接添加它- 脚本执行将被阻止,直到模态返回,所以你可以这样:
var shouldReloadPage = window.showModalDialog('" & sURL & "',null,'status:no;dialogWidth:375px;dialogHeight:550px;dialogHide:true;help:no;scroll:yes;center:yes');
if(shouldReloadPage){
window.location.reload(true);
}
return false;
This is still inside the click handler ofc, just showing in code block for easier reading.
这仍然在点击处理程序 ofc 中,只是显示在代码块中以便于阅读。

