?
Solved

Raising Javascript funtion on clicking of X button of Web form

Posted on 2008-11-02
6
Medium Priority
?
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

718 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