Solved

Raising Javascript funtion on clicking of X button of Web form

Posted on 2008-11-02
6
218 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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