detect IE shutdown or closing form

S

someone

Hi,

Is it possible to detect if the user has shut down the window holding my
ASP2.0 page and/or if the user goes to another page?
For my application I need the user to click on the EXIT button instead of
just going to another page or discard the window completely.

My application is in VB.NET ASP2.0.

thanks,
Eric
 
M

Marina

You can handle the client side onbeforeunload event. However, that event
will fire even if the page is just posting back to itself, so you need to
figure in that code if the user just did something on your form forcing it
to post back, or if it is something else.
 
D

Darren Mart via DotNetMonster.com

As Marina suggested, your best bet is JavaScript and mapping a function to
onbeforeunload:

Your HTML should end something like:

</BODY>
<script language=JavaScript>
function WarnBeforeExit() {
...
}
window.onbeforeunload = WarnBeforeExit();
</script>

One problem you may encounter is that some controls will cause a PostBack, in
which case you don't want the warning. In those cases you'll need to set a
variable/hidden field value so that your WarnBeforeExit() function will be
suppressed in those cases.

Example for your code-behind page:
myButton.Attributes.Add("onclick", "javascript:hdnBypassWarning.
value='true';")

Then in your WarnBeforeExit() function:
if (document.form.hdnBypassWarning.value != 'true')
return 'I DO NOT WANT YOU LEAVING THIS PAGE DAMMIT';


HTH,
Darren
 
S

someone

Thanks, Marina!

Marina said:
You can handle the client side onbeforeunload event. However, that event
will fire even if the page is just posting back to itself, so you need to
figure in that code if the user just did something on your form forcing it
to post back, or if it is something else.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top