469,904 Members | 1,898 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,904 developers. It's quick & easy.

Page unload event

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?
Nov 18 '05 #1
6 18170
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

-----Original Message-----
I have a web form in my application that will be used for both viewing andupdating information. I have a requirement that if any data has been changedon the page and the user attempts to leave the page without saving, the usergets 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 postback, like when the user changes a value in a dropdown list for example.
I attempted to check for IsPostBack, before displaying the save message. Butin that case the save message never gets displayed, even when leaving thepage completely.

Does anyone have any idea how to tackle this problem, or is this animpossible requirement?
.

Nov 18 '05 #2
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.

"Weston Weems" wrote:
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

-----Original Message-----
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?
.

Nov 18 '05 #3
Mike & Weston, see these two articles of mine:

Prompting a User to Save When Leaving a Page
http://www.4guysfromrolla.com/webtech/100604-1.shtml

Using ASP.NET to Prompt a User to Save When Leaving a Page
http://aspnet.4guysfromrolla.com/articles/101304-1.aspx

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #4
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.

-----Original Message-----
Mike & Weston, see these two articles of mine:

Prompting a User to Save When Leaving a Page
http://www.4guysfromrolla.com/webtech/100604-1.shtml

Using ASP.NET to Prompt a User to Save When Leaving a Page http://aspnet.4guysfromrolla.com/articles/101304- 1.aspx
Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
.

Nov 18 '05 #5
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

"Scott Mitchell [MVP]" wrote:
Mike & Weston, see these two articles of mine:

Prompting a User to Save When Leaving a Page
http://www.4guysfromrolla.com/webtech/100604-1.shtml

Using ASP.NET to Prompt a User to Save When Leaving a Page
http://aspnet.4guysfromrolla.com/articles/101304-1.aspx

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!

Nov 18 '05 #6
I went back and turned off the auto postback for my dropdown lists and now it
is working perfectly. Thanks again for your help.

"Weston Weems" wrote:
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.

-----Original Message-----
Mike & Weston, see these two articles of mine:

Prompting a User to Save When Leaving a Page
http://www.4guysfromrolla.com/webtech/100604-1.shtml

Using ASP.NET to Prompt a User to Save When Leaving a

Page
http://aspnet.4guysfromrolla.com/articles/101304-

1.aspx

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
.

Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by David A. Beck | last post: by
1 post views Thread by hal | last post: by
1 post views Thread by Hal | last post: by
3 posts views Thread by Gauthier Segay | last post: by
3 posts views Thread by ABC | last post: by
1 post views Thread by Mariella Bakker | last post: by
5 posts views Thread by =?Utf-8?B?U3RldmVuIFRhbmc=?= | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.