jpandviv
asked on
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;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
Thank you for the points and the grade.
The ASP.net javascript chain supports what you are trying to do already.
<form ... onsubmit="return CheckSessions();">