donde
donde

Reputation:

How do you stop the Next button in a WizardControl?

I am using a WizardControl in .NET 2.0. On the first Step (which is set to StepType="Start") when the next button is clicked, I run server-side validation code. But, no matter what I do it keeps going to the next step. Here is my code:

    Protected Sub Wizard1_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.NextButtonClick

    Dim oUser As New BE.User

    Select Case Wizard1.ActiveStepIndex

        Case 0

            If Membership.FindUsersByName(UserName.Text).Count = 0 Then

                oUser.UserName = UserName.Text
                oUser.Password = Password.Text
                oUser.Email = Email.Text

                Wizard1.ActiveStepIndex = 1
            Else
                Wizard1.ActiveStepIndex = 0
                ErrorMessage.Text = "user name already in use"
            End If
        Case 1

        Case 2


    End Select
End Sub

Upvotes: 1

Views: 3405

Answers (3)

Tim
Tim

Reputation: 28530

As others have mentioned, you can use the Cancel property of the WizardNavigationEventArgs. Here's your code updated to reflect that:

Protected Sub Wizard1_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.NextButtonClick

    Dim oUser As New BE.User

    Select Case Wizard1.ActiveStepIndex
        Case 0
            If Membership.FindUsersByName(UserName.Text).Count = 0 Then
                oUser.UserName = UserName.Text
                oUser.Password = Password.Text
                oUser.Email = Email.Text

                Wizard1.ActiveStepIndex = 1
            Else
                Wizard1.ActiveStepIndex = 0
                ErrorMessage.Text = "user name already in use"
                ' Set the Cancel property to True here
                e.Cancel = True
            End If
        Case 1

        Case 2

    End Select
End Sub

Upvotes: 1

Neha Arora
Neha Arora

Reputation: 41

You can write e.Cancel=true if you are working in any wizard event. Here "e" is an alias for WizardNavigationEventArgs

Upvotes: 4

donde
donde

Reputation:

The Wizard control's NextButtonClick event has a "WizardNavigationEventArgs" parameter that contains a "Cancel" property help to cancel the current next navigation operation.

courtesy of

Steven Cheng Microsoft Online Support

Upvotes: 1

Related Questions