简体   繁体   中英

Modal RadWindow not closing in Chrome

I have a main "Report" page that has some actions the user can take that will open a modal RadWindow, let the user take actions, then click Save and the modal window will close and the main grid refreshes.

This works fine in both IE and Firefox, but Chrome does all the "work" but the modal page stays open. This is only true if I hit the Save button; the Cancel button and the close button on the top of the form still work correctly.

This is the JavaScript from the child window:

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

This is the parent's refreshgrid function:

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

The parent loads the modal window by running:

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

The child's save button has a lot of work done in the code behind and then finishes with this:

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

The cancel button is set up as this:

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

I found one entry from awhile back that suggested adding window.open('', '_self', ''); to the close, but that didn't seem applicable (and also didn't work when I tested it for the heck of it).

EDIT: When running Chrome with the Console open, I do see that I'm getting an error on the main page when refreshgrid is running:

Cannot call method 'ajaxRequest' of null

But not sure if that's what's causing the problem or not. Looking into it more now.

EDIT2: So the issue does seem to be that when using Chrome, the RadAjaxManager from the Master page does not seem to be found by the time refreshGrid runs, which is the reason for the null error above. I was able to "fix" the problem by replacing the guts of the refreshGrid function with document.location.reload(); and it does fine. I'd rather not reload the whole page if I can help it, though, so wondering if there's a way to fix this, still. And I'm curious why IE and Firefox seem to handle this when Chrome doesn't?

More information that may be useful: The main page's Page_Load event:

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

    }

Remove the call to SetUrl("") because it starts disposing the current page and if the browser is fast enough it will not get to the call to close().

if you need to navigate the RadWindow away you can use one of these three options

  • set its ReloadOnShow property to true. Usually together with ShowContentDuringLoad=false

  • set DestroyOnClose to true. Use with caution and add a timeout before close()

  • use the OnClientClose event to set the url to a blank page

OK, I found that Chrome does consistently "lose" the report page's master page reference, or at least the RadAjaxManager there while Firefox and IE do not (I can trace through and watch $find work for both of them).

What I did find, however, is that Chrome (and the other two) can consistently find the main grid of the report (which is what refreshGrid was ultimately looking for). So I was able to replace the guts of refreshGrid with:

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

and get the behavior I was looking for. It's cleaner as well; the original version of refreshGrid looks like it might have originally been intended to do more than just rebind the grid, but by the time I was looking at it, that's all it was really doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM