views:

40

answers:

0

I have a wizard control that I am adding dynamic steps to that will not show the step on the first refresh. I have to click another button for it to show. My Dynamic creations are inside the onInit so I am not sure why this is happening. Please let me know what I am doing wrong.

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        if (!this.DesignMode)
        {
            GatherForms();
            LoadForms();
        }

    }
// Looks in the Forms directory and loads all UC's into the CheckBoxList
    private void GatherForms()
    {

        var files = Directory.GetFiles(Request.PhysicalApplicationPath + "Forms\\", "*.ascx");

        foreach (var file in files)
        {
            // Get the filename and load the control for each file
            var info = new FileInfo(file);
            var control = LoadControl("/Forms/" + info.Name);
            var form = control as FormUserControl;

            // If it's a FormUserControl...
            if (form != null)
            {
                // ... display it in the CheckBoxList
                chklApplications.Items.Add(new ListItem(form.Name(), "/Forms/" + info.Name));

            }
        }

    }

    // Populates the SelectedForms list with selected forms from the checkboxlist
    private void PopulateForms(object sender)
    {
        CheckBoxList chkl = (CheckBoxList)sender;
        Hashtable hash = new Hashtable();
        if (SelectedForms != null)
        {
            SelectedForms = null;
        }

        foreach (ListItem li in chkl.Items)
        {
            if (li.Selected)
            {
                string cname = li.Text;
                hash.Add(cname, li.Value);

            }
        }
        SelectedForms = hash;
    }

    // Dynamically loads the forms that have been checked and added to SelectedForms
    private void LoadForms()
    {
        Hashtable ids = SelectedForms;
        if (ids != null)
        {
            int loc = 2;
            foreach (DictionaryEntry item in ids)
            {
                string formPath = (string)item.Value;

                WizardStepBase newStep = new WizardStep();
                newStep.ID = "wzStep" + item.Key;
                newStep.Title = "- " + item.Key + " Request";
                var form = LoadControl(formPath);
                form.ID = "uc" + item.Key.ToString();
                newStep.Controls.Add(form);
                wzAccessRequest.WizardSteps.AddAt(loc, newStep);
                loc++;


            }
        }

    }

Thanks for the help!