473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 18403
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Justin Bartels | last post by:
Hi, I have been struggling with an unusual problem with a dropdownlist web control for quite some time now. Cutting straight to the problem, I am setting the selected item in the dropdownlist...
1
by: David A. Beck | last post by:
I have a frameset with an index frame and a main frame. The aspx pages in the main frame are loaded based on the hyperlinks clicked in the index frame. In any aspx page in the main frame I want to...
1
by: hal | last post by:
I have an application that includes an activex component that consumes resources that must be released when the a page is unloaded. Toward this end I subscribe to the unload event of the body...
1
by: Hal | last post by:
My most sincere gratitude to anyone who can help me work around this! I have work that needs to be done in javascript on the client whenever a page is unloaded. To this end, I subscribe to...
3
by: Gauthier Segay | last post by:
Hello, I've an application where all my pages implement a PAGE_CODE string property, this property is stored in HttpContext.Current.Items. In some page, I must persist data in session while...
3
by: ABC | last post by:
Has there Page unload event available? I want to write some codes to release memory. But I can not found the Page_Unload event.
1
by: Mariella Bakker | last post by:
Hi All, In an ASP.NET project I am trying to improve performance. As it is now there seems to be a huge bottleneck between the end of the Page.PreRender event and the beginning of the...
1
by: abirami elango | last post by:
Hi, i have created a web application in vb.net. i have assigned a value to the textbox during page UNLOAD event as below.. ......... Protected Sub Page_Unload(ByVal sender As Object, ByVal e As...
5
by: =?Utf-8?B?U3RldmVuIFRhbmc=?= | last post by:
It seems that one page XBAP whose Unloaded event never get called, I need put some clearing stuff (I.G stop dispatcher time) when user close browser, it unload event doesn't work, where shall I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.