This is a migrated thread and some comments may be shown as answers.

Cant execute code from a freed script

1 Answer 81 Views
Window
This is a migrated thread and some comments may be shown as answers.
Nathan
Top achievements
Rank 2
Nathan asked on 18 Jan 2012, 11:31 PM
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>



1 Answer, 1 is accepted

Sort by
0
Nathan
Top achievements
Rank 2
answered on 18 Jan 2012, 11:35 PM
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;
    }
}
Tags
Window
Asked by
Nathan
Top achievements
Rank 2
Answers by
Nathan
Top achievements
Rank 2
Share this question
or