Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Page unload event

Reply
Thread Tools

Page unload event

 
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      11-17-2004
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?
 
Reply With Quote
 
 
 
 
Weston Weems
Guest
Posts: n/a
 
      11-17-2004
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?
>.
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      11-17-2004
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?
> >.
> >

>

 
Reply With Quote
 
Scott Mitchell [MVP]
Guest
Posts: n/a
 
      11-17-2004
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
Reply With Quote
 
Weston Weems
Guest
Posts: n/a
 
      11-17-2004
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
> (E-Mail Removed)
> http://www.4GuysFromRolla.com
>
>* When you think ASP.NET, think 4GuysFromRolla.com!
>.
>

 
Reply With Quote
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      11-18-2004
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
> (E-Mail Removed)
> http://www.4GuysFromRolla.com
>
> * When you think ASP.NET, think 4GuysFromRolla.com!
>

 
Reply With Quote
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      11-18-2004
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
> > (E-Mail Removed)
> > http://www.4GuysFromRolla.com
> >
> >* When you think ASP.NET, think 4GuysFromRolla.com!
> >.
> >

>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What does "Page Load" and "Page Unload", "Page Life Cycle" exactlymean???? lander ASP .Net 5 03-03-2008 02:06 PM
What happens between Page.PreRender and Page.Unload event? Mariella Bakker ASP .Net 1 05-08-2006 09:49 AM
Has there Page unload event available? ABC ASP .Net 3 12-20-2005 10:18 AM
Page Unload Event David A. Beck ASP .Net 1 11-20-2003 07:36 PM
dropdown list selecteditem changes after page.unload event Justin Bartels ASP .Net 2 10-21-2003 02:35 AM



Advertisments