Solved

Raising Javascript funtion on clicking of X button of Web form

Posted on 2008-11-02
6
217 Views
Last Modified: 2013-12-17
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?
0
Comment
Question by:vali66
6 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22864985
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>

0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22865007
0
 

Author Comment

by:vali66
ID: 22865013
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??
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22865452
as per my knowlede No other way  is available
0
 
LVL 7

Expert Comment

by:moseack
ID: 22865686
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

0
 

Accepted Solution

by:
vali66 earned 0 total points
ID: 22866071
Hi moseack,
                   Thanks for the suggestion.But how do differentiate the normal closing (when the status is 100%) and Unexpected closing(not equal to 100%).

As in the both cases the form gets unloaded.For each percentage change (the form gets loaded and then unloaded) as I am running this under a thread.

Specifically I want to capture the event when the user explicitly clicked on X button of browser.

Any other alternative..


Thanks,
Shaikshavali.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question