Open an ASP.Net page containing a Wizard at a different WizardStep to the default starting step?

StackOverflow https://stackoverflow.com/questions/5079357

  •  04-12-2019
  •  | 
  •  

Question

I've got an ASP.Net Forms page containing the following (simplified) <asp:Wizard /> control. I now need to modify this page so that when it is loaded, it loads showing the final step.

Is this possible to do without re-arranging the Wizard steps (Which I'd rather not do)?

<asp:UpdatePanel runat="server" ID="updpanHeader" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Wizard ID="Wizard1" runat="server" DisplaySideBar="false" 
          Style="width: 100%"
          NavigationStyle-CssClass="invisible"
          OnNextButtonClick="Wizard1_NextButtonClick"
          OnActiveStepChanged="Wizard1_ActiveStepChanged">
            <WizardSteps>
                <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1"
                  StepType="Start">
                    ... wizard form controls for page 1 ...
                </asp:WizardStep>
                <asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2"
                  StepType="Step">
                    ... wizard form controls for page 2 ...
                </asp:WizardStep>
                <asp:WizardStep ID="WizardStep3" runat="server" Title="Step 3"
                  StepType="Step">
                    ... wizard form controls for page 3 ...
                </asp:WizardStep>
            </WizardSteps>
        </asp:Wizard>
    </ContentTemplate>
</asp:UpdatePanel>



I've tried swapping the StepType of the first and last steps.

I've also tried changing the ActiveStepIndex in the Page_Load and Page_LoadComplete methods, which does work..

void Page_Load(object sender, EventArgs e)
{
    Wizard1.ActiveStepIndex = (Wizard1.WizardSteps.Count - 1);
}

..but causes Internet Explorer to show a script warning: "An error has occurred in the script on this page. Error: Object expected"

Thanks for your help!

Was it helpful?

Solution

I could be wrong, but I think you want to activate the index using an OnInit override, otherwise all post-backs are going to trigger the Page_Load.

Also, I believe you want to use the MoveTo command instead of setting the index. The downfall is you have to use the step's object, but you can get that easily from Wizard.WizardSteps I believe.

e.g.

private override void OnInit(EventArgs e)
{
  this.Wizard1.MoveTo(this.WizardStep3);

  base.OnInit(e);
}

I may be wrong here though... Please someone correct me if I am.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top