Page unload event

Discussion in 'ASP .Net' started by =?Utf-8?B?TWlrZQ==?=, Nov 17, 2004.

  1. 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?
     
    =?Utf-8?B?TWlrZQ==?=, Nov 17, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?TWlrZQ==?=

    Weston Weems Guest

    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?
    >.
    >
     
    Weston Weems, Nov 17, 2004
    #2
    1. Advertising

  3. 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?
    > >.
    > >

    >
     
    =?Utf-8?B?TWlrZQ==?=, Nov 17, 2004
    #3
  4. Scott Mitchell [MVP], Nov 17, 2004
    #4
  5. =?Utf-8?B?TWlrZQ==?=

    Weston Weems Guest

    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
    >
    > http://www.4GuysFromRolla.com
    >
    >* When you think ASP.NET, think 4GuysFromRolla.com!
    >.
    >
     
    Weston Weems, Nov 17, 2004
    #5
  6. 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
    >
    > http://www.4GuysFromRolla.com
    >
    > * When you think ASP.NET, think 4GuysFromRolla.com!
    >
     
    =?Utf-8?B?TWlrZQ==?=, Nov 18, 2004
    #6
  7. 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
    > >
    > > http://www.4GuysFromRolla.com
    > >
    > >* When you think ASP.NET, think 4GuysFromRolla.com!
    > >.
    > >

    >
     
    =?Utf-8?B?TWlrZQ==?=, Nov 18, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Justin Bartels
    Replies:
    2
    Views:
    1,005
    Jacob Yang [MSFT]
    Oct 21, 2003
  2. David A. Beck

    Page Unload Event

    David A. Beck, Nov 20, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    5,440
    Jim Cheshire [MSFT]
    Nov 20, 2003
  3. ABC
    Replies:
    3
    Views:
    3,089
    Teemu Keiski
    Dec 20, 2005
  4. Mariella Bakker
    Replies:
    1
    Views:
    5,259
    John Timney \( MVP \)
    May 8, 2006
  5. lander
    Replies:
    5
    Views:
    2,605
    Mark Rae [MVP]
    Mar 3, 2008
Loading...

Share This Page