Show or hide wizard steps with code

protected void Wizard1_Load(object sender, System.EventArgs e)
{
 Generic.List OriginalWizardStepTitles = new Generic.List();
 if (ViewState("OriginalWizardStepTitles") != null) {
  OriginalWizardStepTitles = ViewState("OriginalWizardStepTitles");
 }
 if (OriginalWizardStepTitles.Count == 0) {
  foreach (WizardStep PageWizardStep in Wizard1.WizardSteps) {
   OriginalWizardStepTitles.Add(PageWizardStep.Title);
  }
  ViewState("OriginalWizardStepTitles") = OriginalWizardStepTitles;
 }
}

protected void Wizard1_PreRender(object sender, System.EventArgs e)
{
 Generic.List AllowedWizardStepList = new Generic.List();
 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);
 Generic.List OriginalWizardStepTitles = new Generic.List();
 OriginalWizardStepTitles = ViewState("OriginalWizardStepTitles");
 foreach (WizardStep PageWizardStep in Wizard1.WizardSteps) {
  int PageWizardStepIndex = 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))) {
   PageWizardStep.Title = OriginalWizardStepTitles.Item(PageWizardStepIndex);
  }
 }
}

protected void Wizard1_ActiveStepChanged(object sender, System.EventArgs e)
{
 if (string.IsNullOrEmpty(Wizard1.ActiveStep.Title)) {
  Wizard1.ActiveStepIndex += 1;
 }
}

No comments:

Post a Comment