Asp – How to validate fields when using the asp.net wizard control

asp.netvalidation

I have a wizard control in my asp.net 2.0 project, and it contains a few steps. The second step has a textbox with a standard requiredfieldvalidator control attached to it. When the user clicks Next and the box is empty, the validator complains, all is normal.

However, when the user uses the sidebar steps to skip to the next-to-last step, and clicks Finish, the validator is not fired, and the textbox is empty. In my backend, I have this:

    Protected Sub wizard_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles wizard.FinishButtonClick
        If Page.IsValid Then
            ...
        Else
            lblError.Text = "You missed some fields, please return and enter them"
            e.Cancel = True
        End If
    End Sub

(lblError is a label on the complete page, but that's not really the issue)

This code does not work…

What is a good solution to this problem? Remove the sidebar and just not use it? Hardly the nicest solution…

Best Answer

It's far from perfect, but I'm now using this as an answer:

    Protected Sub wzrdAddEvent_SideBarButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles wzrdAddEvent.SideBarButtonClick
        If e.NextStepIndex > (e.CurrentStepIndex + 1) Then
            e.Cancel = True
        End If
    End Sub

"if using the sidebar steps, only allow one step forward at the most"