473,701 Members | 2,728 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 18423
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
3942
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
4602
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
2651
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
2927
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
3210
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
1312
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
3713
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
1883
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
5897
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
8649
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8977
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
8934
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
7824
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...
1
6571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5904
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3102
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
2
2398
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.