我有一个向导控件,我正在添加动态步骤,这不会显示第一次刷新的步骤。我必须单击另一个按钮才能显示。我的动态创作在onInit中,所以我不确定为什么会这样。请让我知道我做错了什么。
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++;
}
}
}
感谢您的帮助!