Stopping Page Unload

  • Thread starter Thread starter David C
  • Start date Start date
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
 
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).



--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
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).



--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************

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
 
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.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top