Solved

Raising Javascript funtion on clicking of X button of Web form

Posted on 2008-11-02
6
212 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now