Page unload event

G

Guest

I have a web form in my application that will be used for both viewing and
updating information. I have a requirement that if any data has been changed
on the page and the user attempts to leave the page without saving, the user
gets prompted with a message asking if they want to save changes.

It seemed logical to put any code to handle this in the page unload event,
however the page unload event gets fired every time the page does a post
back, like when the user changes a value in a dropdown list for example.

I attempted to check for IsPostBack, before displaying the save message. But
in that case the save message never gets displayed, even when leaving the
page completely.

Does anyone have any idea how to tackle this problem, or is this an
impossible requirement?
 
W

Weston Weems

I too have this requirement, I've been able to use both
onUnLoad, and onBeforeUnload() to catch the request to
leave the page, however I havent been able to distinguish
between page reload/postback and going away from the page.

I figured if there was a way I could know what the new url
was, I'd be ok, but doesnt seem that information is
avaliable at the time hte unload event is fired off.

If you find any more information on this... please do post
it here.

Thanks
Weston Weems
 
G

Guest

I will. I've been struggling with this for a few days and noticed your post
after I had already posted mine. I tried the suggestion that someone replied
to you with and it doesn't work any better.
 
W

Weston Weems

Scott,

This was a very informative read... I basically have a
single object I want to monitor (which I can handle and
emit the proper javascript variables myself) However when
I use similar code to check for confirm, and it always
fires on every postback, even if I've got needsToConfirm =
false in form submit.
 
G

Guest

Scott,

I tried the potential solution outlined in the second article you
referenced. While it helped simplify the process of adding this functionality
to the page, it didn't quite solve my overall problem. That is when I make a
change to a dropdown list, that I also want to monitor for changes, it fires
the function to display the prompt to save message. Ideally this function
would not fire unless I was actually leaving the page and not when doing a
postback.

Is this something that can be accomplished or have I been tasked with a
requirement that is impossible to fulfill?

Thank you for your input.

Mike
 
G

Guest

I went back and turned off the auto postback for my dropdown lists and now it
is working perfectly. Thanks again for your help.
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top