javascript Confirm dialog before going to next step in asp .net 2 wizard control

I'm trying to create a scenario where a user will have to answer a question before being able to continue to the next step on a asp .net 2 wizard control.  I have tried to hijack the __DoPostBack code which doesn't quite work.  The javascript confirm will appear, but no matter what they choose the wizard will continue to the next step.  What I need is to basically cancel the postback event when the user hits 'Cancel' in the box.  Is this possible?
This is code from my .js file.  It seems to hijack just fine, but I need to have it stop the submit:
 
 
var __oldDoPostBack;
var __formName='form1';
 
 
function hijackDoPostBack()
{
   try{
      __oldDoPostBack = __doPostBack;
      __doPostBack = runOnSubmit(); 
   }
   catch(ex){ 
        alert('hijackDoPostBack: error: ' + ex.toString());
      lastExceptionLocation = "hijackDoPostBack";
      lastException = ex;
   }
}
function runOnSubmit(eventTarget, eventArgument)
{
         
           
       if(CheckSessions()==true)
        {
            __oldDoPostBack(eventTarget, eventArgument);
        }
        else
        {
             //here is where it will end up if the user selects 'Cancel' from the confirm box
       }
 
}
 
function CheckSessions()
{      
    var bConfrim=true;
   //any onsubmit functions here
   if(!btnWhichButton || (btnWhichButton.value=='Add Sessions' || btnWhichButton.value==''))
    {
        bConfirm=false
    } 
    else 
    {
         bConfirm=confirm('Are these all of the session you want to have covered?  Click Ok to continue or Cancel to add more sessions.');
    }
   btnWhichButton='';
   CheckSesssions=bConfirm; 
}

Open in new window

jpandvivAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ChetOS82Commented:
Why not, rather than hijacking the __doPostBack function, just define an onsubmit function for the form.  If that method returns false, then the submit is cancelled.

The ASP.net javascript chain supports what you are trying to do already.

<form ... onsubmit="return CheckSessions();">
0
prairiedogCommented:
>>>I'm trying to create a scenario where a user will have to answer a question before being able to continue to the next step on a asp .net 2 wizard control.
Can you not use validator to force user to answer the question before you move on?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jpandvivAuthor Commented:
Thank you very much.  I guess I was making this issue much more difficult than it should have been.  Not too uncommon I suppose.  I ended up creating a hidden control that kept the value of the javascript confirm box and using a custom validator with a javascript procedure to test for the answer to the confirm.  Of course, I had to default the hidden control to 'true' so that it would only work for certain steps.  Thanks again.  I gave you an 'A' on this one.
0
prairiedogCommented:
Thank you for the points and the grade.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.