views:

659

answers:

2

I wish to allow the user an option to navigate away from a Register page. However the register page is an ASP:Wizard with RequiredFieldValidators.

How can I fix this without removing the RequiredFieldValidators? The "Next" button of the wizard seems to be built-in to the Wizard control and doesn't seem to let me apply a ValidationGroup property, which seems to be the typical way to handle this situation.

Thanks

A: 

Could you put another button outside of the wizard labelled 'Cancel' or 'Skip' and set the CausesValidation property to False?

Ryan ONeill
this sounds to be a solution that would work but would greatly diminish from the refined user interface I am attempting to create.
HaterTot
+1  A: 

From http://forums.asp.net/p/1022184/1385194.aspx

After searching over and over on how to validate my wizard control steps, i came up with these solutions. Remember that each step should have it's own validation group. For these sample i use "Form" as my validation group.

1) Validation on the next button click. For this one, i simply override the Previous and Next button autogenerated by the Wizard Control by using 2 asp:Button. You then set the cause validation to true and you assign a validation group. Note that the important part is in the CommandName section.

<StepNavigationTemplate >
<asp:Button ID="btnPrevious" runat="server" CssClass="WizardControlButton" Text="Previous" CommandName="MovePrevious"  />
<asp:Button ID="btnNext" runat="server" CssClass="WizardControlButton" CommandName="MoveNext" Text="Next" CausesValidation="true" ValidationGroup="Form" />
</StepNavigationTemplate>

2) Validation on Sidebar click This one is also simple. You add the code in the SideBarButtonClick event of your control and then you check the step id you are currently. After it validates the page with the validation group in parameters. If the page is not valid. It cancel the event.

Protected Sub wizRegistration_SideBarButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles wizRegistration.SideBarButtonClick
    If wizRegistration.ActiveStep.ID = "wizSelectPostalCode" AndAlso e.NextStepIndex > e.CurrentStepIndex Then
        Page.Validate("Form")
        If Not Page.IsValid() Then
            e.Cancel = True   
        End If
    End If
End Sub
Greg
thanks so much. I can't believe i couldn't find this myself. It works!notes to anybody who finds this solution in the future: if you need to override the first step of your wizard's button, use <StartNavigationTemplate>. Also, remember to wire up the wizRegistration_SideBarButtonClick event in your <asp:Wizard> tag.
HaterTot