Tips and tricks for .NET using ASP and VB code.

Show or hide wizard steps with code

    Protected Sub Wizard1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Wizard1.Load
Dim OriginalWizardStepTitles As New Generic.List(Of String)
If ViewState("OriginalWizardStepTitles") IsNot Nothing Then
OriginalWizardStepTitles = ViewState("OriginalWizardStepTitles")
End If
If OriginalWizardStepTitles.Count = 0 Then
For Each PageWizardStep As WizardStep In Wizard1.WizardSteps
OriginalWizardStepTitles.Add(PageWizardStep.Title)
Next PageWizardStep
ViewState("OriginalWizardStepTitles") = OriginalWizardStepTitles
End If
End Sub

Protected Sub Wizard1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Wizard1.PreRender
Dim AllowedWizardStepList As New Generic.List(Of String)
AllowedWizardStepList.Add(Wizard1.WizardSteps.Item(0).Title)
'Only the steps added here will be visible.
AllowedWizardStepList.Add("Step 1")
AllowedWizardStepList.Add("Step 3")
AllowedWizardStepList.Add(Wizard1.WizardSteps.Item(Wizard1.WizardSteps.Count - 1).Title)
Dim OriginalWizardStepTitles As New Generic.List(Of String)
OriginalWizardStepTitles = ViewState("OriginalWizardStepTitles")
For Each PageWizardStep As WizardStep In Wizard1.WizardSteps
Dim PageWizardStepIndex As Integer = PageWizardStep.Wizard.WizardSteps.IndexOf(PageWizardStep)
'Hide all wizard steps.
PageWizardStep.Title = ""
'Show a wizard step only if it is the allowed list.
If AllowedWizardStepList.Contains(OriginalWizardStepTitles.Item(PageWizardStepIndex)) Then
PageWizardStep.Title = OriginalWizardStepTitles.Item(PageWizardStepIndex)
End If
Next
End Sub

Protected Sub Wizard1_ActiveStepChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Wizard1.ActiveStepChanged
If Wizard1.ActiveStep.Title = "" Then
Wizard1.ActiveStepIndex += 1
End If
End Sub

No comments:

Post a Comment

Search This Blog