Confirming leaving the page.....

Discussion in 'ASP .Net' started by UJ, Aug 10, 2005.

  1. UJ

    UJ Guest

    I've got a page where users can make changes (enable and disable some
    checkboxes.) I need to have it so that if they have made changes and go away
    from the page, they will get prompted if they want to lose their changes
    before the changes are actually saved. So I've got code that adds a
    javascript window.confirm on unload to stop them. Problem is, the check
    boxes are run at the server which means whenever somebody clicks one, the
    page thinks it's unloading to it prompts them which isn't what I want. I
    only want them to be prompted when they are going elsewhere.

    Anybody have any suggestions on what I can do to fix this?

    TIA - Jeffrey.
     
    UJ, Aug 10, 2005
    #1
    1. Advertising

  2. UJ

    Curt_C [MVP] Guest

    UJ wrote:
    > I've got a page where users can make changes (enable and disable some
    > checkboxes.) I need to have it so that if they have made changes and go away
    > from the page, they will get prompted if they want to lose their changes
    > before the changes are actually saved. So I've got code that adds a
    > javascript window.confirm on unload to stop them. Problem is, the check
    > boxes are run at the server which means whenever somebody clicks one, the
    > page thinks it's unloading to it prompts them which isn't what I want. I
    > only want them to be prompted when they are going elsewhere.
    >
    > Anybody have any suggestions on what I can do to fix this?
    >
    > TIA - Jeffrey.
    >
    >


    tie a local variable to the onBlur event of the checkbox

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com
     
    Curt_C [MVP], Aug 10, 2005
    #2
    1. Advertising

  3. UJ

    UJ Guest

    I don't understand what you mean to put a variable in the onBlur event. Sure
    I can set a local variable and now I know that something is happened. But
    when the person clicks the checkbox, and the page is sent to the server, the
    onunload event is called which fires, it sees that there has been a change
    so it asks the user if they want to lose the changes then reloads itself.

    Are you saying though - check for the variable in the onunload and if the
    variable is set, don't do anything because that means that the page isn't
    really going to unload - and then reset the variable ? I'm not sure how to
    do that.

    TIA - Jeffrey.

    "Curt_C [MVP]" <software_at_darkfalz.com> wrote in message
    news:...
    > UJ wrote:
    >> I've got a page where users can make changes (enable and disable some
    >> checkboxes.) I need to have it so that if they have made changes and go
    >> away from the page, they will get prompted if they want to lose their
    >> changes before the changes are actually saved. So I've got code that adds
    >> a javascript window.confirm on unload to stop them. Problem is, the check
    >> boxes are run at the server which means whenever somebody clicks one, the
    >> page thinks it's unloading to it prompts them which isn't what I want. I
    >> only want them to be prompted when they are going elsewhere.
    >>
    >> Anybody have any suggestions on what I can do to fix this?
    >>
    >> TIA - Jeffrey.
    >>
    >>

    >
    > tie a local variable to the onBlur event of the checkbox
    >
    > --
    > Curt Christianson
    > site: http://www.darkfalz.com
    > blog: http://blog.darkfalz.com
     
    UJ, Aug 10, 2005
    #3
  4. one method would be setting a flag at client side when the check boxes are
    clicked and validate that flag inside the unload function

    This will be a global flag at client side, on page load set it to true

    var FireUnloadPrompt = true;

    check boxes will call a client side function oncheck / uncheck

    chk1.Attributes.Add("onclick" , "ChecUncheck();")

    ChecUncheck()
    {
    FireUnloadPrompt = false;
    return(true);
    }

    in Window.Unload fucntion

    if(FireUnloadPrompt)
    code to call window.confirm...

    Wouldnt this work?


    "UJ" wrote:

    > I've got a page where users can make changes (enable and disable some
    > checkboxes.) I need to have it so that if they have made changes and go away
    > from the page, they will get prompted if they want to lose their changes
    > before the changes are actually saved. So I've got code that adds a
    > javascript window.confirm on unload to stop them. Problem is, the check
    > boxes are run at the server which means whenever somebody clicks one, the
    > page thinks it's unloading to it prompts them which isn't what I want. I
    > only want them to be prompted when they are going elsewhere.
    >
    > Anybody have any suggestions on what I can do to fix this?
    >
    > TIA - Jeffrey.
    >
    >
    >
     
    =?Utf-8?B?U3JlZWppdGggUmFt?=, Aug 10, 2005
    #4
  5. UJ

    Curt_C [MVP] Guest

    UJ wrote:
    > I don't understand what you mean to put a variable in the onBlur event. Sure
    > I can set a local variable and now I know that something is happened. But
    > when the person clicks the checkbox, and the page is sent to the server, the
    > onunload event is called which fires, it sees that there has been a change
    > so it asks the user if they want to lose the changes then reloads itself.
    >
    > Are you saying though - check for the variable in the onunload and if the
    > variable is set, don't do anything because that means that the page isn't
    > really going to unload - and then reset the variable ? I'm not sure how to
    > do that.
    >
    > TIA - Jeffrey.
    >
    > "Curt_C [MVP]" <software_at_darkfalz.com> wrote in message
    > news:...
    >
    >>UJ wrote:
    >>
    >>>I've got a page where users can make changes (enable and disable some
    >>>checkboxes.) I need to have it so that if they have made changes and go
    >>>away from the page, they will get prompted if they want to lose their
    >>>changes before the changes are actually saved. So I've got code that adds
    >>>a javascript window.confirm on unload to stop them. Problem is, the check
    >>>boxes are run at the server which means whenever somebody clicks one, the
    >>>page thinks it's unloading to it prompts them which isn't what I want. I
    >>>only want them to be prompted when they are going elsewhere.
    >>>
    >>>Anybody have any suggestions on what I can do to fix this?
    >>>
    >>>TIA - Jeffrey.
    >>>
    >>>

    >>
    >>tie a local variable to the onBlur event of the checkbox
    >>
    >>--
    >>Curt Christianson
    >>site: http://www.darkfalz.com
    >>blog: http://blog.darkfalz.com

    >
    >
    >


    You will have to turn off the auto-postback

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com
     
    Curt_C [MVP], Aug 10, 2005
    #5
    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. RSB
    Replies:
    6
    Views:
    7,699
    Karim
    May 19, 2004
  2. =?Utf-8?B?TXBob3ph?=

    Confirming Deletes in a DataGrid

    =?Utf-8?B?TXBob3ph?=, Aug 6, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    439
    =?Utf-8?B?UmF2aWthbnRoW01WUF0=?=
    Aug 6, 2004
  3. darrel
    Replies:
    6
    Views:
    498
    darrel
    Jun 14, 2005
  4. Darrel
    Replies:
    3
    Views:
    8,911
    Laurent Bugnion
    Apr 26, 2006
  5. MRW

    Confirming a Deletion

    MRW, Nov 20, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    346
Loading...

Share This Page