Solved

Raising Javascript funtion on clicking of X button of Web form

Posted on 2008-11-02
6
214 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

914 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

16 Experts available now in Live!

Get 1:1 Help Now