动态控制未在回发时显示
我有一个向其添加动态步骤的向导控件,该控件在第一次刷新时不会显示该步骤。我必须单击另一个按钮才能显示它。我的动态创作位于 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++;
}
}
}
感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论