Stopping Page Unload

D

David C

Does anyone know how to flag that a change has been made to any control on
an aspx page? I would assume it would be on the client side somehow. If a
change has been made to a control on a server control, e.g. FormView,
GridView, etc. I want to keep the user from closing (unloading) the web page
until they have saved their changes using the update or insert buttons.
Thanks.

David
 
G

Gregory A. Beamer

Does anyone know how to flag that a change has been made to any
control on an aspx page? I would assume it would be on the client side
somehow. If a change has been made to a control on a server control,
e.g. FormView, GridView, etc. I want to keep the user from closing
(unloading) the web page until they have saved their changes using the
update or insert buttons. Thanks.


the only way I know is to emit JavaScript that sets a dirty flag and then
hook it to all controls the user can change. You then have other JavaScript
that warns the user they need to save or cancel changes before they can
exit, not PREVENT them from closing (realistically, they can always go into
task manager and kill the app despite your best efforts to stop them).
 
D

David C

Gregory A. Beamer said:
the only way I know is to emit JavaScript that sets a dirty flag and then
hook it to all controls the user can change. You then have other
JavaScript
that warns the user they need to save or cancel changes before they can
exit, not PREVENT them from closing (realistically, they can always go
into
task manager and kill the app despite your best efforts to stop them).

I have tried using the onbeforeunload event but it is only supported in IE I
think. It does not work in Firefox. Where would I put the "warning" code to
prompt them? Thanks.

David
 
G

Gregory A. Beamer

I have tried using the onbeforeunload event but it is only supported
in IE I think. It does not work in Firefox. Where would I put the
"warning" code to prompt them? Thanks.

Try onunload and set the return to false if the user selects cancel. You
can also force a postback if they click the okay button, although
posting back means, essentially, pushing the submit button.

You have to return false to stop events from completing. It has been
awhile since I played seriously with JavaScript, and I am a bit strapped
for time over at least the next week, so I am not sure I will be able to
find a solution if it does not work.

I saw a site lately, by a "reputable" company (I think it was when I was
searching for webhosts) that had a "wait! we have a special deal" popup.
There was an OK button (to continue the unload) and a cancel button. If
I hit cancel, it would take me to the deal or something (I clicked away
and refused to return to the site, as this type of thing really pisses
me off). I wish I had the link right now.
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top