Stopping Page Unload

Discussion in 'ASP .Net' started by David C, Aug 7, 2009.

  1. David C

    David C Guest

    Does anyone know how to flag that a change has been made to any control on
    an aspx page? I would assume it would be on the client side somehow. If a
    change has been made to a control on a server control, e.g. FormView,
    GridView, etc. I want to keep the user from closing (unloading) the web page
    until they have saved their changes using the update or insert buttons.
    Thanks.

    David
    David C, Aug 7, 2009
    #1
    1. Advertising

  2. "David C" <> wrote in
    news::

    > Does anyone know how to flag that a change has been made to any
    > control on an aspx page? I would assume it would be on the client side
    > somehow. If a change has been made to a control on a server control,
    > e.g. FormView, GridView, etc. I want to keep the user from closing
    > (unloading) the web page until they have saved their changes using the
    > update or insert buttons. Thanks.



    the only way I know is to emit JavaScript that sets a dirty flag and then
    hook it to all controls the user can change. You then have other JavaScript
    that warns the user they need to save or cancel changes before they can
    exit, not PREVENT them from closing (realistically, they can always go into
    task manager and kill the app despite your best efforts to stop them).



    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
    Gregory A. Beamer, Aug 7, 2009
    #2
    1. Advertising

  3. David C

    David C Guest

    "Gregory A. Beamer" <> wrote in message
    news:Xns9C6087CDEA03Fgbworld@207.46.248.16...
    > "David C" <> wrote in
    > news::
    >
    >> Does anyone know how to flag that a change has been made to any
    >> control on an aspx page? I would assume it would be on the client side
    >> somehow. If a change has been made to a control on a server control,
    >> e.g. FormView, GridView, etc. I want to keep the user from closing
    >> (unloading) the web page until they have saved their changes using the
    >> update or insert buttons. Thanks.

    >
    >
    > the only way I know is to emit JavaScript that sets a dirty flag and then
    > hook it to all controls the user can change. You then have other
    > JavaScript
    > that warns the user they need to save or cancel changes before they can
    > exit, not PREVENT them from closing (realistically, they can always go
    > into
    > task manager and kill the app despite your best efforts to stop them).
    >
    >
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > Twitter: @gbworld
    > Blog: http://gregorybeamer.spaces.live.com
    >
    > *******************************************
    > | Think outside the box! |
    > *******************************************


    I have tried using the onbeforeunload event but it is only supported in IE I
    think. It does not work in Firefox. Where would I put the "warning" code to
    prompt them? Thanks.

    David
    David C, Aug 7, 2009
    #3
  4. "David C" <> wrote in
    news::

    > I have tried using the onbeforeunload event but it is only supported
    > in IE I think. It does not work in Firefox. Where would I put the
    > "warning" code to prompt them? Thanks.


    Try onunload and set the return to false if the user selects cancel. You
    can also force a postback if they click the okay button, although
    posting back means, essentially, pushing the submit button.

    You have to return false to stop events from completing. It has been
    awhile since I played seriously with JavaScript, and I am a bit strapped
    for time over at least the next week, so I am not sure I will be able to
    find a solution if it does not work.

    I saw a site lately, by a "reputable" company (I think it was when I was
    searching for webhosts) that had a "wait! we have a special deal" popup.
    There was an OK button (to continue the unload) and a cancel button. If
    I hit cancel, it would take me to the deal or something (I clicked away
    and refused to return to the site, as this type of thing really pisses
    me off). I wish I had the link right now.


    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
    Gregory A. Beamer, Aug 10, 2009
    #4
    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:
    975
    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,390
    Jim Cheshire [MSFT]
    Nov 20, 2003
  3. Mariella Bakker
    Replies:
    1
    Views:
    5,211
    John Timney \( MVP \)
    May 8, 2006
  4. lander
    Replies:
    5
    Views:
    2,517
    Mark Rae [MVP]
    Mar 3, 2008
  5. Larry Woods
    Replies:
    10
    Views:
    333
    Michael D. Kersey
    Jul 8, 2004
Loading...

Share This Page