动态控制未在回发时显示

发布于 2024-09-25 17:33:08 字数 2414 浏览 7 评论 0原文

我有一个向其添加动态步骤的向导控件,该控件在第一次刷新时不会显示该步骤。我必须单击另一个按钮才能显示它。我的动态创作位于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文