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

OnClientClose fires mulitple times

5 Answers 188 Views
Window
This is a migrated thread and some comments may be shown as answers.
Angie
Top achievements
Rank 1
Angie asked on 16 Oct 2008, 07:04 PM
I'm using the example from 
http://demos.telerik.com/aspnet/prometheus/Window/Examples/CommunicationBetweenRadWindows/DefaultCS.aspx

to load a radwindow, specifically the following code:

  function openWin()  
        {  
            var oWnd = radopen("SegmentTable.aspx?st=1", "RadWindow1");  
            oWnd.setSize(340,340);  
            //set a function to be called when RadWindow is closed  
              
            oWnd.add_close(OnClientClose);  
        }  
          
        function OnClientClose(oWnd)  
        {  
            alert('wtf');  
        } 


If the user opens the radwindow more than once, the OnClientClose is fired for each time it has been opened. 

What do I need to do to fix this?  Can I destroy the radwindow once it's initially closed so that when it's opened it doesn't get mulitple close events added.

I suppose I can work around by having a flag to make sure the oWnd.add_close doesn't do anything after the first time, but I'm just wondering if this is intended behavior.  I have no way of determining if it fires multiple times in the demo.

Thanks.


Update:  I tried the hidden flag trick, but that doesn't work as the window does lose it's OnClientClose atttribute on postback. 

5 Answers, 1 is accepted

Sort by
0
Angie
Top achievements
Rank 1
answered on 16 Oct 2008, 10:50 PM
Ah, I guess I just needed to add

DestroyOnClose

 

="true"

to the window manager.

It would be nice if this could be added to the Demo.  Would have saved me lots of time.  Thanks.

 

0
Georgi Tunev
Telerik team
answered on 17 Oct 2008, 05:31 AM
Hello Angie,

This behavior is expected. Indeed, if you don't destroy the window object, the closing function will be added every time. You need to either set DestroyOnClose to true, or to use the standard remove_close() ASP.NET AJAX method.



Best wishes,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
NS
Top achievements
Rank 1
answered on 12 Jun 2009, 08:56 AM
Can you give an example on how to use the remove_close function.

I have the following code in my webform that is included in the Radwindow:

<script language="javascript" 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 OnClientClose() {  
                GetRadWindow().BrowserWindow.InitiateAjaxRequest('AppFilter');  
                GetRadWindow().Close();  
            }  
            </script>  

In my situation I can't use DestroyOnClose=true, so I would happy to know on how to implement remove_close() method in my code.

Thanks,
Nicolas
0
Princy
Top achievements
Rank 2
answered on 12 Jun 2009, 10:04 AM
Hi,

Try calling client side function which is in parent page if you want to remove the OnClientClose event handler from RadWindow page. See the example below.

Parent Page:
ASPX:
 
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">  
<Windows> 
    <telerik:RadWindow runat="server" ID="Win1" NavigateUrl="win1.aspx" OnClientClose="OnClientClose" OpenerElementID="Button1"></telerik:RadWindow> 
</Windows> 
</telerik:RadWindowManager> 
<input id="Button1" type="button" value="button" /> 

JavaScript:
 
<script type="text/javascript">  
function OnClientClose()  
{  
    alert('Hi');  
 
}  
function RemoveClose(oWnd)  
{  
    oWnd.remove_close(OnClientClose);  
}  
</script> 

Page opened in RadWindow:
ASPX:
 
<input id="Button2" type="button" value="Close Window" onclick="CloseWindow();" /> 

JavaScript:
 
<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 CloseWindow()  
{    
    GetRadWindow().BrowserWindow.RemoveClose(GetRadWindow());  
    GetRadWindow().Close();      
}    
</script> 

Hope this helps,
Princy.
0
NS
Top achievements
Rank 1
answered on 12 Jun 2009, 12:27 PM
Thanks it works.

Actually in the RemoveClose function I had to set oWnd.URL to something to get it working. I found this on the following blog http://blogs.telerik.com/blogs/09-06-04/common_radwindow_issues_and_their_solution.aspx
Tags
Window
Asked by
Angie
Top achievements
Rank 1
Answers by
Angie
Top achievements
Rank 1
Georgi Tunev
Telerik team
NS
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or