【问题标题】:Modal RadWindow not closing in Chrome模态 RadWindow 未在 Chrome 中关闭
【发布时间】:2013-03-20 18:49:23
【问题描述】:

我有一个主“报告”页面,其中包含用户可以执行的一些操作,这些操作将打开一个模态 RadWindow,让用户执行操作,然后单击“保存”,模态窗口将关闭并且主网格刷新。

这在 IE 和 Firefox 中都可以正常工作,但 Chrome 会完成所有“工作”,但模式页面保持打开状态。仅当我点击“保存”按钮时,这才是正确的;表单顶部的取消按钮和关闭按钮仍然可以正常工作。

这是来自子窗口的 JavaScript:

<script type="text/javascript">
    function GetRadWindow() {
        var oWindow = null;
        if (window.radWindow)
            oWindow = window.radWindow;
        else if (window.frameElement.radWindow)
            oWindow = window.frameElement.radWindow;
        return oWindow;
    }

    function CloseRadWindow() {
        var oWnd = GetRadWindow()
        oWnd.SetUrl("");
        oWnd.close();
    }

    function CloseAndRebind(args) {
        var oWnd = GetRadWindow()
        oWnd.BrowserWindow.refreshGrid(args);
        oWnd.SetUrl("");
        oWnd.close();
    }
</script>

这是父级的refreshgrid函数:

    <script type="text/javascript">
        function refreshGrid(arg) {
            if (!arg) {
                $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("Rebind");
            }
            else {
                $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("RebindAndNavigate");
            }
        }
    </script>

父级通过运行加载模态窗口:

    protected void btnSplitInvoice_Click(object sender, EventArgs e)
    {
        var btn = sender as Button;
        var item = (GridDataItem)btn.Parent.Parent;

        long id = long.Parse(item["Id"].Text);
        var itemType = this.TabStrip1.SelectedIndex == 0 ? "TransferOrderInvoice" : "EquipmentInvoice";

        string scriptstring = "var oWindow=radopen('../Misc/SplitInvoice.aspx?id=" + id + "&type=" + itemType + "','SplitInvoice');oWindow.SetModal(true);";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "openwindow", scriptstring, true);
    }

孩子的保存按钮在后面的代码中做了很多工作,然后就这样结束了:

ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "mykey", "CloseAndRebind('navigateToInserted');", true);

取消按钮是这样设置的:

<button type="button" class="CancelBtn" value="" onclick="CloseRadWindow()">
                        </button>

我发现不久前有一个条目建议在结尾添加window.open('', '_self', '');,但这似乎不适用(而且当我测试它时也不起作用)。

编辑:在控制台打开的情况下运行 Chrome 时,我确实看到当 refreshgrid 运行时我在主页上遇到错误:

Cannot call method 'ajaxRequest' of null

但不确定这是否是导致问题的原因。现在进一步研究。

EDIT2:所以问题似乎是在使用 Chrome 时,在 refreshGrid 运行时似乎没有找到主页面中的 RadAjaxManager,这就是上述 null 错误的原因。我能够通过用document.location.reload(); 替换 refreshGrid 函数的胆量来“解决”这个问题,而且效果很好。不过,如果我能提供帮助,我宁愿不重新加载整个页面,所以想知道是否有办法解决这个问题。我很好奇为什么 IE 和 Firefox 似乎可以处理这个问题,而 Chrome 却没有?

更多可能有用的信息:主页的 Page_Load 事件:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.Session["AllUserLocationValue"] = string.Empty;

            this.InitializeThePage();
        }

        RadAjaxManager manager = RadAjaxManager.GetCurrent(this.Page);
        manager.AjaxRequest += this.manager_AjaxRequest;

        manager.AjaxSettings.AddAjaxSetting(manager, this.pnlHeading, this.RadAjaxLoadingPanel1);
        manager.AjaxSettings.AddAjaxSetting(manager, this.RadCodeBlock1, this.RadAjaxLoadingPanel1);

    }

【问题讨论】:

    标签: c# javascript asp.net telerik


    【解决方案1】:

    删除对 SetUrl("") 的调用,因为它开始处理当前页面,如果浏览器足够快,它就不会调用 close()。

    如果您需要导航 RadWindow,您可以使用这三个选项之一

    • 将其 ReloadOnShow 属性设置为 true。通常与 ShowContentDuringLoad=false 一起使用

    • 将 DestroyOnClose 设置为 true。谨慎使用并在 close() 之前添加超时

    • 使用 OnClientClose 事件将 url 设置为空白页面

    【讨论】:

    • 感谢您的建议:SetUrl("");在这种情况下,它并没有影响问题,但是根据您的解释,我可以看到不使用它的价值。问题似乎是 refreshGrid 中的 $find 找不到母版页的 RadAjaxManager 的 ClientId,据我所知。
    • 这很奇怪。尝试创建一个单独的函数来返回这个引用,并确保它的脚本标签不是任何部分回发的一部分;或一个全局 JS 变量,它将保存管理器的 CLIentID,因此您可以轻松调试它以获得所需的 ID。您也可以随时使用简单的 __doPostBack() 或隐藏按钮并单击()它。
    【解决方案2】:

    好的,我发现 Chrome 确实“丢失”了报告页面的母版页引用,或者至少那里的 RadAjaxManager 没有,而 Firefox 和 IE 没有(我可以追踪并观察 $find 对它们的工作) .

    然而,我确实发现 Chrome(和其他两个)可以始终如一地找到报告的主网格(这是 refreshGrid 最终要寻找的)。所以我能够将refreshGrid 的胆量替换为:

    function refreshGrid(arg) {
                var radgridNotApproved = $find("<%= rgNotApproved.ClientID %>").get_masterTableView();
                radgridNotApproved.rebind();
            }
    

    并获得我正在寻找的行为。它也更干净; refreshGrid 的原始版本看起来可能原本打算做的不仅仅是重新绑定网格,但当我看到它时,它实际上就是这样做的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-20
      • 2012-02-09
      • 1970-01-01
      • 2012-07-09
      • 2011-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多