RadWindow close error

3 posts, 0 answers
  1. Emil
    Emil avatar
    19 posts
    Member since:
    Oct 2012

    Posted 22 Jan 2013 Link to this post

    I use a RadWindow to add a new row in a RadGrid. The content of this 'add new record' window is nothing much..  a RadComboBoxes and a few RadNumericTextBoxes and two buttons: Add and Close.

    When the windows closes (add button is clicked, close button is clicked or I close it with the upper-right X), an error appears:
    Microsoft JScript runtime error: Can't execute code from a freed script

    This is the javascript code used to show 'add new record' window from the main window where the grid is:
    function DisplayAddWindow() {
       var parentPage = GetRadWindow().BrowserWindow;
       var parentRadWindowManager = parentPage.GetRadWindowManager();
       var oWnd2 = parentRadWindowManager.open("AddNewRecordWindow.aspx", "rwAddWindow");
       window.setTimeout(function () {
          oWnd2.set_title("Add new record");
          oWnd2.setActive(true);
          oWnd2.set_modal(true);
          oWnd2.setSize(370, 240);
          oWnd2.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close);
          oWnd2.set_visibleStatusbar(false);
          oWnd2.set_showContentDuringLoad(false);
          oWnd2.center();
          oWnd2.add_close(RefreshGrid);
       }, 0);
       return false;
    }
     
    function RefreshGrid(oWnd, eventArgs) {
       $find("<%= RadAjaxManager1.ClientID%>").ajaxRequest("RefreshGrid");
    }

    To rebind the grid, after the 'add new record' windows closes, I use an ajaxRequest (RefreshGrid function).

    This is where I think the problem lies: If I remove theoWnd2.add_close(RefreshGrid); statement the problem dissapears but the ajaxRequest doesn't fire (the grid doesn't refresh).

    I've read a few posts about this error, but I can't get it to work.

    Please help! Thank you!
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 24 Jan 2013 Link to this post

    Hello Emil,

    It seems your grid is already in a RadWindow (judging from the GetRadWindow() in the beginning of the function), and you open the AddWindow from the main page. This means that its context is the main page and not the page that has your grid, so adding a close handler in that page should not be done. What I can suggset is adding the handler in the markup of the main page and in that function call the refreshGrid() function in the content page  through JavaScript. You can pass a reference to the current RadWindow in a custom field in the second on to store it. For example:
    function DisplayAddWindow()
    {
        var currWnd = GetRadWindow();
        var parentPage = currWnd.BrowserWindow;
        var parentRadWindowManager = parentPage.GetRadWindowManager();
        var oWnd2 = parentRadWindowManager.open("AddNewRecordWindow.aspx", "rwAddWindow");
        oWnd2._gridWndReference = currWnd;
        window.setTimeout(function ()
        {
            oWnd2.set_title("Add new record");
            oWnd2.setActive(true);
            oWnd2.set_modal(true);
            oWnd2.setSize(370, 240);
            oWnd2.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close);
            oWnd2.set_visibleStatusbar(false);
            oWnd2.set_showContentDuringLoad(false);
            oWnd2.center();
            //oWnd2.add_close(RefreshGrid);
        }, 0);
        return false;
    }

    and in the parent page:
    <telerik:RadWindow ID="rwAddWindow" OnClientClose="OnClientClose" runat="server">
    </telerik:RadWindow>
    <script type="text/javascript">
        function OnClientClose(sender, args)
        {
            sender._gridWndReference.get_contentFrame().contentWindow.refreshGrid();
        }
    </script>
    Calling functions in different windows is explained here: http://www.telerik.com/help/aspnet-ajax/window-programming-calling-functions.html.


    Another thing that can cause such an error are other similar cross-frame references for scripts when DestroyOnClose is set to true for either popup (or for its manager), so setting it to false may help, if it is an option in your case.

    Regards,
    Marin Bratanov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Emil
    Emil avatar
    19 posts
    Member since:
    Oct 2012

    Posted 24 Jan 2013 Link to this post

    Thank you, Marin!

    I've already solved it using code-behind to open the second window.
Back to Top