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: