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

Posted on 2008-11-18
Medium Priority
Last Modified: 2012-05-05
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()
      __oldDoPostBack = __doPostBack;
      __doPostBack = runOnSubmit(); 
        alert('hijackDoPostBack: error: ' + ex.toString());
      lastExceptionLocation = "hijackDoPostBack";
      lastException = ex;
function runOnSubmit(eventTarget, eventArgument)
            __oldDoPostBack(eventTarget, eventArgument);
             //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=confirm('Are these all of the session you want to have covered?  Click Ok to continue or Cancel to add more sessions.');

Open in new window

Question by:jpandviv
  • 2
LVL 18

Expert Comment

ID: 22994112
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();">
LVL 22

Accepted Solution

prairiedog earned 1000 total points
ID: 22994539
>>>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?

Author Closing Comment

ID: 31518297
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.
LVL 22

Expert Comment

ID: 22995583
Thank you for the points and the grade.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question