3

This is driving me nuts. I've reviewed and tried answers from these SO threads, to no avail:

CreateUserWizard step changing issue after account creation

Advancing wizard from code-behind in ASP.NET

Prevent Navigation to CreateUserWizardStep in the Postback event of nextbutton

I have added a wizardstep before the one that creates the user on the database:

(0) Personal Details

(1) Sign Up for Your New Account

(2) Complete

In step 0, I have a (dreaded) reCaptcha. Navigation template for step 0:

    <StartNavigationTemplate>
        <asp:Button ID="StartNextButton" runat="server" CommandName="MoveNext" Text="Next"  OnClick="StartNextButton_Click" CausesValidation="true"/>
    </StartNavigationTemplate>

Here, I validate the reCaptcha in the codebehind. This handler declaration was created by VS2012. If the validation fails, should re-load (and navigate to) the step:

    protected void StartNextButton_Click(object sender, EventArgs e)
    {
        recaptcha.Validate();
        if (! recaptcha.IsValid)
        {
            RegisterUser.ActiveStepIndex = 0;
            RegisterUser.MoveTo(RegisterUser.ActiveStep);              
        }
    }

Ideally ( and what I've done in earlier versions ) is to set e.Cancel = true when validation fails. Since VS is only passing EventArgs e, Cancel isn't available, thus the twiddling of ActiveStep.

Debugging shows validation is working, but on validation failure - despite setting the ActiveStepIndex to 0 - I'm passed to Step 1.

Any tips would be appreciated.

Community
  • 1
  • 1
Tim Lacy
  • 31
  • 3
  • Of course, once I posted this, I came up with several alternative ways to accomplish this, but they are either a hack, or a change to the workflow I wanted. There still should be a way to do this. – Tim Lacy Sep 26 '13 at 15:29
  • I wound up putting the recaptcha at the end of step 1, and all was well. – Tim Lacy Feb 16 '14 at 21:57

1 Answers1

2

The wizard will not stop going to the next step here. You need to define the OnNextButtonClick and use this event to cancel moving to next Wizard step.

<asp:Wizard OnNextButtonClick="RegisterUser_NextButtonClick" ID="RegisterUser" 
     runat="server">

protected void RegisterUser_NextButtonClick(object sender, WizardNavigationEventArgs e)
 {
           if(RegisterUser.ActiveStep==0)
               {
                 recaptcha.Validate();
                    if (! recaptcha.IsValid)
                        {
                            e.Cancel = true;
                        }            
                }
      return;
}
R.C
  • 10,417
  • 2
  • 35
  • 48