[英]Refresh the main page on close of popup window
我从服务器端使用以下代码打开弹出窗口
var url = string.Format("../UserPopup.aspx?user_Ids={0}&fromDate={1}&toDate={2}", user_Ids, fromDate, toDate);
string script = string.Format("function f(){{openDialog('{0}', {1}, {2}, {3});Sys.Application.remove_load(f);}}Sys.Application.add_load(f);",
url,
"true",
1000,
300);
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "someKey", script, true)
以下是用于关闭javascript弹出窗口的代码。 以下代码无法正常工作。
function GetRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function Close() {
var result = window.confirm("Are you sure you want to close the window!");
if (result == true) {
var oWindow = GetRadWindow();
oWindow.argument = null;
oWindow.onunload = refreshParent;
oWindow.close();
return false;
}
}
function refreshParent() {
window.opener.location.reload();
}
window.opener.location.reload();
在这里根本不起作用。 不知道原因。
如何在弹出窗口关闭时刷新父页面?
使用OnClientClose事件,类似于:
在主页上
<telerik:RadWindow ID="RadWindow1" runat="server" OnClientClose="OnClientClose"></telerik:RadWindow>
<script>
function OnClientClose(sender, args) {
if (args.get_argument()) { //make the condition more complex, depending on the argument you pass
window.location.href = window.location.href;
}
}
</script>
在内容页面上
function Close() {
var result = window.confirm("Are you sure you want to close the window!");
if (result == true) {
var oWindow = GetRadWindow();
oWindow.close(someArugment); //pass the argument here. Define it first, of course
}
}
该演示还提供了一个有效的示例, http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product = window
您可以为此使用局部视图模型,首先将以下代码添加到局部视图中,并在主视图中添加“ mymodel”,
<div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel">Event Information</h4> </div> <div id='myModal' class='modal'> <div class="modal-dialog"> <div class="modal-content"> <div id='myModalContent'></div> </div> </div> </div>
现在,这里是您的关闭按钮javascript文件,其中只隐藏了“ mymodel”控件
$(function () { $("#closbtn").click(function () { $('#myModal').modal('hide'); }); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.