【问题标题】:Refresh the main page on close of popup window在弹出窗口关闭时刷新主页
【发布时间】:2017-02-05 00:54:23
【问题描述】:

我正在从服务器端使用以下代码打开弹出窗口

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(); 在这里根本不起作用。不知道原因。

如何在弹出窗口关闭时刷新父页面?

【问题讨论】:

  • 所以你的意思是说你不能关闭子窗口也不能刷新父窗口对吧?
  • 如果我从Close 函数中删除oWindow.onunload = refreshParent;,我可以关闭窗口。我只需要刷新页面。

标签: javascript c# asp.net telerik


【解决方案1】:

使用 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

【讨论】:

    【解决方案2】:

    您可以为此使用局部视图模型,首先将以下代码添加到局部视图并在主视图中添加“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');
            });
        });

    【讨论】:

    • 您的两个代码都抛出错误,我无法使用您的代码。这是我的代码的一个巨大变化。我为此使用 Telerik RadWindow。
    • 我在这里使用 RadWindow。
    • 我正在从服务器端打开弹出窗口。因此,我无法使用您的代码。
    猜你喜欢
    • 1970-01-01
    • 2016-12-19
    • 2012-06-03
    • 2011-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    相关资源
    最近更新 更多