473,757 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 18430
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******@4guysf romrolla.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******@4guysf romrolla.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******@4guysf romrolla.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******@4guysf romrolla.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
3947
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 using the IndexOf method of the list's items collection (in my debugging case this successfully sets the selectedindex to 15). After postback, the selecteditem is always the first item in the list, losing the selection I set previously (And
1
4605
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 save the information in the various controls before the new aspx page is loaded. I thought I could use the Page event Unload, but it does not seem to be triggering when the aspx page is replaced in the frame by another aspx page.
1
2654
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 of my page in javascript. However, if I turn on smart navigation, any button that does a server.transfer fails to fire the javascript unload event.
1
2934
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 the unload event (client side not server side) of the <body> HTML element through javascript.
3
3212
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 the user perform operation on this page (postback navigation based). I also need to clean up the session data when the user leave the page (by a anyway). My question is about the Unload event, is it safe to use the unload
3
1320
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
3716
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 Page.Unload event. Using a performance analyzing tool (AqTime 4.9) I am not able to find out what is happening between these 2 events. Can anyone shine some light on what is normally going on between these 2 events? Thanks in advance.
1
1888
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 System.EventArgs) Handles Me.Unload txtPopConfirm.Text = intCountAnswer1 End Sub
5
5900
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 put? -- ======================= Steven Tang SYWWUYU)
0
9487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10069
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8736
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3828
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.