Cant execute code from a freed script

2 posts, 0 answers
  1. Nathan
    Nathan avatar
    52 posts
    Member since:
    Apr 2011

    Posted 18 Jan 2012 Link to this post

    Hello,

    I'm using a modal dialog which is a RadWindow. The page should present an alert using "radalert" if the user has not saved their work. When the save button is clicked a hidden field is updated "hdnIsModified". When the close button is clicked, the "ClosePage()" function is called which passes an argument to the calling page if the page has been modified. Before the page closes, "onBeforeWindowClose" is called to determine if the alert should be displayed.

    The problem is that I'm getting an error message (Cant execute code from a freed script) if the user makes a change to a dropdown list inside the RadAjaxPanel, then clicks "save", then "Cancel". If the user does not change the dropdown list and only clicks "save", then "cancel", it works fine. The dropdown list causes an ajax request since it's inside the radajaxpanel. Any ideas why this could interfere with the RadAlert logic? The "Save" and "Cancel" buttons are not inside the RadAjaxPanel.


    RadWindow as Modal:
    function SavingChanges() {
        var hdn = document.getElementById('<%=hdnIsModified.ClientID %>');
        if (hdn) {
            hdn.value = 'true';
        }
    }
     
    function ClosePage() {
        var oModifications = document.getElementById('<%=hdnIsModified.ClientID %>');
        if (oModifications.value.toLowerCase() == "true") {
            GetRadWindow().close('reload');
        } else {
            GetRadWindow().close();
        }
    }
     
    function onBeforeWindowClose(oWinow, args) {
        function callbckFunction(confirmResult) {
            if (confirmResult) {// confirmResult == true
                // Close this RadWindow
                // First remove the handler in order to avoid recursion
                oWinow.remove_beforeClose(onBeforeWindowClose);
     
                oWinow.close();
                 
                // Reattach the handles after the window is closed.
                // RECOMMENDATION: If the DestroyOnClose="true" property is set in in the RadWindow's declaration,
                // then remove this line of the code:
                oWinow.add_beforeClose(onBeforeWindowClose);
            }
        }
     
        // Close the window: If modifications exist, reload parent grid by passing argument
        var oModifications = document.getElementById('<%=hdnIsModified.ClientID %>');
        if (oModifications.value.toLowerCase() != "true") {
            // Cancel closing
            args.set_cancel(true);
     
            // Show a rad confirmation dialog
            var sMsg = "Are you sure you want to cancel " + document.getElementById('<%=Mode.ClientID %>').value.toLowerCase() + "ing" + " the new requirement?";
            radconfirm(sMsg, callbckFunction, 400, 150, null, "Confirm");
        }
     
     
    }
     
    function GetRadWindow() {
        var oWindow = null;
        if (window.radWindow)
            oWindow = window.radWindow;
        else if (window.frameElement.radWindow)
            oWindow = window.frameElement.radWindow;
        return oWindow;
    }
     
    function pageLoad() {
        // Get the RadWindoiw object that contains this page
        var oWindow = GetRadWindow();
     
        // Attach RadWindow's OnClientBeforeClose handler
        oWindow.add_beforeClose(onBeforeWindowClose);
    }
     
    function pageUnload() {
        // Get the RadWindoiw object that contains this page
        var oWindow = GetRadWindow();
     
        // NOTE! If the DestroyOnClose="true" is set in the RadWindow's declaration,
        // then the oWindow object will be 'null'.
        if (oWindow) {
            // Detach RadWindow's OnClientBeforeClose handler
            oWindow.remove_beforeClose(onBeforeWindowClose);
        }
    }



    <asp:Button ID="Save" runat="server"
         Text="Save" onclick="Save_Click" OnClientClick="SavingChanges();" />
     <input id="butCancel" type="button" value="Cancel" onclick="ClosePage();" />
     
    <div style="margin-left: 15px; margin-right: 10px; margin-top: 8px; margin-bottom: 8px">
         <hr />
         <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1" >
                 <div ID="DataEntryArea" class="span-22 last" runat="server">
                 </div>
         </telerik:RadAjaxPanel>
         <hr style="margin:0.5em 0 0 0" />
     </div>



  2. Nathan
    Nathan avatar
    52 posts
    Member since:
    Apr 2011

    Posted 18 Jan 2012 Link to this post

    Resolved!!

    Fixed issue using a flag to indicate the event has already been attached.. 

    function pageLoad() {
        if (hasAttachedEvent == false) {
            var oWindow = GetRadWindow();
            oWindow.add_beforeClose(onBeforeWindowClose);
     
            hasAttachedEvent = true;
        }
    }
Back to Top