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

OnClientClose not working (as expected)

9 Answers 261 Views
Window
This is a migrated thread and some comments may be shown as answers.
Ole Albers
Top achievements
Rank 2
Ole Albers asked on 29 Jan 2009, 03:23 PM
Hi.

I'm trying to do some fancy stuff when my radwindow is closed (using the 'x'). Therefore I use the onClientClose-Event of the RadWindowManager (as noticed in different forum-topics here)

So my site looks like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DetailEmail.aspx.cs" Inherits="waPMHI.dlg.DetailEmail" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
 
<head runat="server"
    <title>E-Mail</title> 
    <meta http-equiv="Content-type" content="application/xhtml+xml; charset=utf-8" /> 
    <link rel="stylesheet" type="text/css" href="../Styles/pmhi.css" /> 
 <telerik:RadCodeBlock ID="RadCodeBlock12" runat="server">     
    <script language="javascript" type="text/javascript"
// [... other functions ...] 
 function machzu() { 
            alert('zu'); 
        } 
    </script> 
    </telerik:RadCodeBlock> 
</head> 
<body class="mailTableBack""> 
 
<telerik:RadWindowManager ID="SingletonSkinFix" runat="server"  Skin="Web20" OnClientClose="machzu()"/> 
 
           
    <form id="wrapper" runat="server"  
    style="height: 100%; width: 100%; "
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"
     <telerik:RadScriptManager ID="RadScriptManager1" runat="server" ></telerik:RadScriptManager>   
<telerik:/RadAjaxPanel> 
<%-- [... a lot of other stuff ...] --%> 
</form></body></html> 
But the function "machzu" is *not* opened when I close the window. Instead it opens at the beginning (just like an onload-Event)

Any idea why there is this weird behaviour?


9 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Jan 2009, 07:13 AM
Hi Ole,

I am not sure what is happening at your end. I tried the scenario and it is working fine on my end. You should put only the function's name without the ( and ) brackets as a value of the OnClientClose property. Try removing the brackets in the function call and see whether it is working fine.

ASPX:
<telerik:RadWindowManager ID="SingletonSkinFix" runat="server"  OnClientClose="machzu"
<Windows> 
    <telerik:RadWindow ID="window1" runat="server" VisibleOnPageLoad="true" NavigateUrl="http://www.google.com"></telerik:RadWindow> 
</Windows> 
</telerik:RadWindowManager> 

JavaScript:
<script language="javascript" type="text/javascript">  
 function machzu() 
 {  
     alert('Window Closed');  
 }  
</script>  

Thanks,
Shinu.
0
Lenin
Top achievements
Rank 1
answered on 31 Jan 2009, 01:34 PM
Hi Ole,

try with this....

function

openRadWindow(CustomerID)

 

{

 

var oWnd = radopen("AddPopup.aspx?CustomerID=" + CustomerID, "RadWindow1" );

 

oWnd.Center();

oWnd.add_close(OnClientCloseWin);

 

}

 

function OnClientCloseWin()

 

{

alert(

"Clsoing");

 

}

<html>
on click of any buttons open the window like onclik="openRadWindow('test'); return false;"

 

...
then add the function  oWnd.add_close(OnClientCloseWin); .. its working fine....

0
Lenin
Top achievements
Rank 1
answered on 31 Jan 2009, 01:35 PM
Hi Ole,

try with this....

function

openRadWindow(CustomerID)

 

{

 

var oWnd = radopen("AddPopup.aspx?CustomerID=" + CustomerID, "RadWindow1" );

 

oWnd.Center();

oWnd.add_close(OnClientCloseWin);

 

}

 

function OnClientCloseWin()

 

{

alert(

"Clsoing");

 

}

<html>
on click of any buttons open the window like onclik="openRadWindow('test'); return false;"

 

...
then add the function  oWnd.add_close(OnClientCloseWin); .. its working fine....

By
Lenin(tlenin@insoft.com)

0
Svetlina Anati
Telerik team
answered on 02 Feb 2009, 04:21 PM
Hello Ole,

The problem comes from the way you have attached the handler - when you add the brackets (), you actually call and execute the function once. In order to attach a handler you should not call the function, but you should only provide the function's name - in this manner it will not be called once but it will executed every time the particular event fires.


Sincerely yours,
Svetlina
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ole Albers
Top achievements
Rank 2
answered on 03 Feb 2009, 01:08 PM
Thanks for your help. Looks like those brackets were totally wrong.

Well... Still looks like we talk about different stuff...

I do *not* want to react when *another* window I opened before is closed but the window I am actually in at the moment. (So I can save Textfield-Values before closing, etc.)

Is there a KB-Article/Hint/Whatever how to solve that problem?

Just found out it is absolutely the same as in this Topic I want to achieve...: Client Close From Popup Window


0
Ole Albers
Top achievements
Rank 2
answered on 04 Feb 2009, 10:35 AM
I tried the "onbeforeunload"-method I found in the other post.

But the firefox(3.0)-behaviour is a bit weird at this point.

In my case the onbeforeunload-Event is not fired when closing the window by mousclick, but when I reload the page (F5) (which also causes the window to close)

Is this the normal FF-behaviour or am I doing something wrong?
0
Georgi Tunev
Telerik team
answered on 04 Feb 2009, 12:35 PM
Hello Ole,

Let me check if I understand your scenario correctly. You want to validate some element in the content page before closing the window. For example if a textfield is empty, you don't want that RadWindow to be closed until the user fill it, am I right?
If this is so, you can either use OnClientBeforeClose or as an alternative - to remove the closing button from RadWindow by using the Behaviors property and close it only from a button inside the content page. In the last scenario, you would call GetRadWindow.close() only after the validation is successful.

Let me know what approach you would like to use (or if I haven't understood your scenario completely) and I will prepare a small sample that will show how to achieve the desired behavior.


All the best,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ole Albers
Top achievements
Rank 2
answered on 04 Feb 2009, 01:24 PM
Nearly right. I want to save all Data entered automaticly when the window is closed to a DB.

OnClientBeforeClose looks like the right decision but afaik you use it in the radWindowManager of the calling window, not in the window that is opened itself?

In other words:

Window A opens Window B. When window B is closing I want to do some stuff in Window B.

I thought OnClientBeforeClose  just works this way:
Window A opens Window B. When window B is closing I can do some stuff in Window A

Thats what I suspect from the examples.
0
Accepted
Georgi Tunev
Telerik team
answered on 05 Feb 2009, 12:59 PM
Hello Ole,

Yes, the function must be executed in the context of the parent page - the one from which the RadWindow was created. Still you can get a reference to the content page from the parent one and call a function there (in the content) that would validate the fields for your.
Please check the following help topic that shows how to call functions in RadWindow in different scenarios:
http://www.telerik.com/help/aspnet-ajax/window_programmingcallingfunctions.html



Kind regards,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Window
Asked by
Ole Albers
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Lenin
Top achievements
Rank 1
Svetlina Anati
Telerik team
Ole Albers
Top achievements
Rank 2
Georgi Tunev
Telerik team
Share this question
or