Let me first of all wish everybody a very happy new year!:)

I have a present challenge and would like suggestions from you great guys.
I have an aspx web form where I have manually added a wizard control. I then attempted to add the wizard steps dynamically i.e add wizardsteps at runtime.

I am able to load these wizard steps for the first time (in the page_load or page_init event). When I hit the 'next' button to move to the next step it gives an error which says

ActiveViewIndex is being set to '1'.  It must be smaller than the current number of View controls '0'. For dynamically added views, make sure they are added before or in Page_PreInit event.
Parameter name: value

I wanted the first step to be displayed to be the second steps out of the total number of steps.(ie activeviewindex = 1).

Methinks it sorts of loses the viewstate of the of the control and the wizardsteps or views of the multiview controls at postbacks and this assumption is what I have pursued with no success yet :(

I may be wrong hence I need the experts' advice.
Below I have listed the simple codes showing what I have attempted to do.

At page_load or page_init event 

 if (!IsPostBack)
        {

           CreateWizardSteps();
        }
public void CreateWizardSteps(int noofsteps)
    {
        // create the number of wizardstep controls to create and load.
        string sid;
        int g = 0;
        for (int i = 0; i < noofsteps; i++)
        {
          WizardStepBase vws = new  WizardStep();
            g = i + 1;
            sid = "wsId" + g.ToString();
            vws = CreateStep(sid, g);
            wiz.WizardSteps.Add(vws);

        }

   public WizardStepBase CreateStep(string stepID, int sNo)
    {
        //create a wizardstep control

        WizardStepBase myStep = new WizardStep();
        myStep.ID = stepID;
        //create the panel to hold the control
        Panel pnlCtl = new Panel();
        pnlCtl.ID = "pnlCtl" + sNo.ToString();
        //create a new usercontrol
        ctrPg tPg =(ctrPg) Page.LoadControl("~/controls/ctrPg.ascx");
        tPg.ID = "tPg" + sNo.ToString();
        pnlCtl.Controls.Add(tPg);
        myStep.Controls.Add(pnlCtl);
        return myStep;
}

Please note that I had manually added the wizard control named "wiz"

Ideas are needed ASAP:sweat:

first of all do they need to be added dynamically? could you get away with adding them manually first and hiding/showing certain controls. You can set the index of the step so you could technically override this on postback and then alter the index given some requirement you may have.

If you must obtain this dynamically. Then you are required to rebuild all the controls on initialisation.

Example
- Create WizardStep1
- User Goes to Next Step
- On Initialization
--- Rebuild WizardStep1
--- Create WizardStep2
--- Set Index of wizard to 1 (the second step)

There are many tutorials for dynamic control postback state. Here is a good one. http://aspnet.4guysfromrolla.com/articles/092904-1.aspx

thank you man for the idea. I am currently looking at the link.
I will really want it to be dynamic.

Thanks man :)

first of all do they need to be added dynamically? could you get away with adding them manually first and hiding/showing certain controls. You can set the index of the step so you could technically override this on postback and then alter the index given some requirement you may have.

If you must obtain this dynamically. Then you are required to rebuild all the controls on initialisation.

Example
- Create WizardStep1
- User Goes to Next Step
- On Initialization
--- Rebuild WizardStep1
--- Create WizardStep2
--- Set Index of wizard to 1 (the second step)

There are many tutorials for dynamic control postback state. Here is a good one. http://aspnet.4guysfromrolla.com/articles/092904-1.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.