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

Postback when radwindow is closed

4 Answers 725 Views
Window
This is a migrated thread and some comments may be shown as answers.
Scott Smith
Top achievements
Rank 1
Scott Smith asked on 10 Aug 2010, 04:05 PM
I'm attempting to capture the closing of a rad window and do a postback. 

The scenario is this:

1) the RadWindowManager is in the master page with a method to pop the window:
<telerik:RadWindowManager ID="RadWindowManager1" runat="server"
Skin="Office2007"
KeepInScreenBounds="true"
Behaviors="Move, Close"
>
<Windows>
    <telerik:RadWindow runat="server" ID="rwGeneral" 
    AutoSize="true" 
    Modal="true" 
    Title=""  
    OnClientPageLoad="OnClientPageLoad" />
</Windows>
</telerik:RadWindowManager>
function getRadWindow()
{
    return $find('<%# rwGeneral.ClientID %>');
}
function openRadWindow(url, Title) 
{
    var oWnd = getRadWindow();
    if (Title) oWnd.set_title(Title);
    oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Resize)
    oWnd.setUrl(url);
    oWnd.show();
  
    return false;
}

I pop the window from a web control sitting on a page:
function popBranchPicker()
{
    var radWindow = getRadWindow();
    radWindow.add_close(radWindow_OnClientClose);
    openRadWindow('<%= BranchPickerPopupUrl %>', 'Branch Picker');
      
    return false;
}
  
function radWindow_OnClientClose(oWnd, args)
{
    // clean up the close method
    var radWindow = getRadWindow();
    radWindow.remove_close(radWindow_OnClientClose);
  
    // refresh here
    var btnRefresh = document.getElementById('<%= btnRefreshBMDashboardAndPicker.ClientID %>');
    btnRefresh.click();
      
    return false;
}

In the page hosted in the rad window (just a stand-alone page, no master page, etc.) I attach a close handler to cause a post-back:
GetRadWindow().add_close(doClose);
function GetRadWindow()
{
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow; // Will work in Moz in all cases, including clasic dialog
else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; // IE (and Moz az well)
return oWindow;
}
function CloseOnReload()
{
GetRadWindow().Close();
}
function doClose()
{
document.forms[0].submit();
}

In the postback I perform a save and then emit javascript to close the rad window:
// some stuff here
RadAjaxPanel1.ResponseScripts.Add("CloseOnReload();");

Everything appears to work just fine, and does in fact work fine the first time.  The second time I pop the window from the control, however, I get a javascript error:

Message: Can't execute code from a freed script

I've tried all combinations of add_close(), remove_close(), returning false from JS functions, etc. and I can't get it to work correctly.  It seems a little counterintuitive to have to jump through all these hoops to get this functionality anyway, so perhaps there's better way to handle this.

Essentially I'm attempting to have the window perform a code-behind save when it's closed (without having to put a button on the page).

Any ideas?

Thanks

4 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 11 Aug 2010, 01:08 PM
Hello Scott Smith,


Such error occurs in this scenario:
  • A JavaScript function is attached to a event of the RadWindow object. In your case - GetRadWindow().add_close(doClose);. Please note that the functions are attached by reference. This mean, that the address of the function (for example: FFx00), not the name, will be stored in the events collection of the RadWindow object.
  • The function is declared on the page that is opened inside the RadWindow.
  • The page, that is opened inside the RadWindow, is refreshed. For example a postback is triggered from a button. In this case the JavaScript function, which is attached to the OnClientClose, will be recreated as well. This mean that the function's address will be different than before postback occurs. For example:
    Before postback: FFx00
    After postback    : FFxF1
  • Please note that the function's address stored in the RadWindow's event handler collection is the destroyed one:  FFx00
  • In this case, when the RadWindow is closed, the ClientClose event is fired and the not existing function is called - with address FFx00. This is the reason for the message that appears.

The solution in this case is to remove the attached handlers (those that are declared on page that is opened inside the RadWindow) from the RadWnidow's object and this needs to be done before the postback. The code bellow shows an example, how to remove the OnClientClose handler.

Copy Code
function pageUnload()
{
    var oWindow = GetRadWindow();
    oWindow.remove_close(clientCloseHandler);
}

The pageUnload function is called automatically by the MS AJAX framework when the page us unloaded
The code above should be added to the page that is opened inside the RadWindow.

As an alternative, you can examine the scenarios shown in this KB article.
http://www.telerik.com/support/kb/aspnet-ajax/window/radwindow-that-postbacks-and-manipulates-opener-page-on-its-reload.aspx

Greetings,
Georgi Tunev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Scott Smith
Top achievements
Rank 1
answered on 11 Aug 2010, 02:07 PM
Thanks!  That worked great.  The trick was making sure to remove the close handler before the window was destroyed.
0
sharanya
Top achievements
Rank 1
answered on 26 Nov 2010, 02:24 AM
Hi,

I am having the same issue of "cant execute from a freed script" when clicking the close button of radwindow.

It happens only the second time i open and close.

You have suggested that i add remove_close in the pageUnload in the page which radwindow opens. But , how do i access the closeHandler event in the radwindow PAge. The event is in a parent page which is a different project.

thanks & regards,
sharanya
0
Georgi Tunev
Telerik team
answered on 26 Nov 2010, 08:45 AM
Hi sharanya,

I am not sure that I understand your scenario correctly. Note however, that if the parent and the content pages are in different projects / application, you might experience problems with the browser's security that will not allow you to get access to client objects from one page in the other.
In any way, it will be best if you can send me a sample project (in a support ticket) that reproduces your exact setup and the problem that you experience so I can get a better view over your case. I'll check it and will be able to provide you with more specific reply.

Sincerely yours,
Georgi Tunev
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Window
Asked by
Scott Smith
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Scott Smith
Top achievements
Rank 1
sharanya
Top achievements
Rank 1
Share this question
or