Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Confirming When Exiting Without Saving

Confirming When Exiting Without Saving

Scheduled Pinned Locked Moved Web Development
csharpjavascriptasp-nethelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brendan Vogt
    wrote on last edited by
    #1

    Hi, I need help with confirming when exiting without saving. I am using ASP.NET 2.0. I have an .aspx page with a couple of input controls. Then there is a submit button and a cancel button. I have a javascript method that checks if an input field has been changed or not. When the cancel button is clicked this javascript method is fired and displays a pop up message to the user. The thing that I am having difficult to implement is if data in the input was changed, but the user doesn't click the cancel button, but just clicks on another link to another page. If this is the case then I need the javascript method also to fire where the user go to a different page. Please can someone advise? Regards Brendan

    D 1 Reply Last reply
    0
    • B Brendan Vogt

      Hi, I need help with confirming when exiting without saving. I am using ASP.NET 2.0. I have an .aspx page with a couple of input controls. Then there is a submit button and a cancel button. I have a javascript method that checks if an input field has been changed or not. When the cancel button is clicked this javascript method is fired and displays a pop up message to the user. The thing that I am having difficult to implement is if data in the input was changed, but the user doesn't click the cancel button, but just clicks on another link to another page. If this is the case then I need the javascript method also to fire where the user go to a different page. Please can someone advise? Regards Brendan

      D Offline
      D Offline
      dfz
      wrote on last edited by
      #2

      i have used onbeforeunload event to confirm leave, i.e. window.onbeforeunload = function() { if (modified) return "Unsaved changes. Are you sure you want to leave?" }

      B 1 Reply Last reply
      0
      • D dfz

        i have used onbeforeunload event to confirm leave, i.e. window.onbeforeunload = function() { if (modified) return "Unsaved changes. Are you sure you want to leave?" }

        B Offline
        B Offline
        Brendan Vogt
        wrote on last edited by
        #3

        Thanks for this, but I am not sure where to put this in. Here is a basic representation of my code: var isDirty = false; function checkForChange(msg) { if (isDirty) return confirm(msg); else return true; } I hope you can help me on this. Thanks Brendan

        D 1 Reply Last reply
        0
        • B Brendan Vogt

          Thanks for this, but I am not sure where to put this in. Here is a basic representation of my code: var isDirty = false; function checkForChange(msg) { if (isDirty) return confirm(msg); else return true; } I hope you can help me on this. Thanks Brendan

          D Offline
          D Offline
          dfz
          wrote on last edited by
          #4

          Hi, See the modified example below. I would suggest to use temporary functions to avoid javascript memory leaks. I hope this makes sense. var isDirty = false; // this is the message we will show to confirm var default_message = "You have made changes to the data since last saving. If you continue, you will lose these changes."; var checkForChange = function(msg) { if (isDirty) return confirm( !msg ? default_message : msg ); } window.onbeforeunload = function() { return default_message; }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups