在弹出窗口关闭时刷新主页面

本文关键字:刷新 主页 窗口 | 更新日期: 2023-09-27 18:08:58

我打开弹出窗口与以下代码从服务器端

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');
        });
    });