0

I have a Wizard control with just 2 steps at the moment.

The first step has an input to create a directory. When the next button is clicked, if the directory doesn't exist then it is created, I set a variable 'DirCreated' to equal "1" and the wizard moves on to step 2.

I have some javascript like this:

    $(document).ready(function () {
        window.onbeforeunload = function () {
            var dc = document.getElementById('cpMainContent_Wizard_DirCreated');
            if (dc.value == "1") {
                return "You have attempted to leave this page. If you need to make any future changes to this project you must use the Edit Project page. Are you sure you want to exit this page?";
            }
        };
    });

The idea is that if no directory has yet been created the user can navigate to another page without getting prompted, however, if they have created a directory it will warn them about leaving the page. This has a bit of an issue.

If a directory is created, the wizard goes to step 2, if I then click previous the wizard goes to step 1, if I click to navigate away from the page it warns me (which I expect), but, when I click next it warns me as well. I'm not sure why this happens, it doesn't bring up the warning when clicking previous and next doesn't navigate away from the page as such (if I click leave page, then it takes me to step 2 of the wizard on the same page).

What can I do to prevent the warning when clicking the next button?

Family
  • 1,053
  • 1
  • 20
  • 41

0 Answers0