Link to home
Start Free TrialLog in
Avatar of vali66
vali66Flag for India

asked on

Raising Javascript funtion on clicking of X button of Web form

I am working with web forms

ASP.Net 2.0+C#.Net

I am opening a modal dialog window from a parent page.Now when the user closes the modal dialog window by clicking on X button I want to raise a javascript function.How do I do that.I dont want to use onunload event of form...any other way?
Avatar of Gyanendra Singh
Gyanendra Singh
Flag of India image

use this
<BODY onbeforeunload="HandleOnClose()">

Then, add the following JavaScript code into the <HEAD> section of your ASPX page:

<script language="javascript">
<!--

function HandleOnClose() {
   if (event.clientY < 0) {
      event.returnValue = 'Are you sure you want to leave the page?';
   }
}

//-->
</script>

Avatar of vali66

ASKER

The modal dialog window I am using is basically used for progress bar functionality.So this form will get loaded and unloaded at each instance and obviosly I cant use onbeforeunload and onunload.

So Is there any other way of raising javascript function when the user clicks on X button??
as per my knowlede No other way  is available
Hello vali66,

You could use one of the before mentioned events like a dead-men-switch.
Attach your event handler code to handle "unexpected" closure of the window. When the progress bar completes normally, flag this, so the close handler will not run.

<BODY onunload="Body_OnClose()">
 
<script language="javascript">
<!--
var noramlClose = false;
function Body_OnClose()
{
  if (normalClose)
    return;
 
  alert("Unexpected closing");
}
 
//-->
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of vali66
vali66
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial