WebControl 的触发器方法未触发

发布于 2024-07-17 16:19:06 字数 1046 浏览 7 评论 0原文

这是我的场景:
我有一个带有占位符的页面。 该页面动态地向此占位符添加了不同类型的控件(我们不想显示一些数据 - 通过查询字符串或回发获取 id,因为我们还有一棵树)。
添加的控件或多或少都包含一个文本框(显示元素的名称)、复选框(显示元素的活动状态)和一个保存按钮,该按钮触发此 Web 控件内的方法。

现在我的问题非常明显: 当我动态添加控件时(并且对于每个条件:!回发和回发),如此添加的控件内的保存方法不会触发 - 无论我做什么......

我只是太愚蠢了诀窍:)

一些幕后信息(工作流程):

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.Page.IsPostBack)
    {
        this.SelectedElement = SomeMagicMethod();
    }
}

protected void NodeSelected(object sender, TreeViewNodeEventArgs e)
{
    this.SelectedElement = SomeOtherMagicMethod();
}

protected override void OnLoadComplete(EventArgs e)
{
    // we have to take this life-cycle!
    if (this.SelectedElement!= null)
    {
        this.DisplayElement();
    }
}

private void DisplayElement()
{
    var UC = this.LoadControl(UCPath) as DataTypeUC;
    if (UC == null)
    {
        return;
    }

    UC.ID = EditCampaignFolderUCID;
    UC.SetData(this.SelectedElement);
    UC.DataBind();
    this.phContent.Controls.Add(UC);
}

this is my scenario:
i have a page with a placeholder. the page adds dynimcally different kinds of controls (we wan't to display some data - getting the id via querystring or postback, as we also have a tree) to this placeholder.
the added controls all, more or less, contain a textbox (name of the displaying element), checkbox (active-state of the displaying element) and a save-button which fires a method inside this webcontrol.

now my problem is really obvious:
as i'm adding the control dynamically (and for every condition: !Postback and Postback), the save-method inside the so added control, won't fire - regardless what i do ...

i'm simply to stupid to get the trick :)

some behind-the-scene-infos (workflow):

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.Page.IsPostBack)
    {
        this.SelectedElement = SomeMagicMethod();
    }
}

protected void NodeSelected(object sender, TreeViewNodeEventArgs e)
{
    this.SelectedElement = SomeOtherMagicMethod();
}

protected override void OnLoadComplete(EventArgs e)
{
    // we have to take this life-cycle!
    if (this.SelectedElement!= null)
    {
        this.DisplayElement();
    }
}

private void DisplayElement()
{
    var UC = this.LoadControl(UCPath) as DataTypeUC;
    if (UC == null)
    {
        return;
    }

    UC.ID = EditCampaignFolderUCID;
    UC.SetData(this.SelectedElement);
    UC.DataBind();
    this.phContent.Controls.Add(UC);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蛮可爱 2024-07-24 16:19:06

动态添加控件时,您还必须每次都连接保存按钮的事件(即,如果保存按钮是动态生成的)。

While adding controls dynamically, you'll also have to wire up the event of the save button everytime (that is, if the save button is being generated dynamically).

如此安好 2024-07-24 16:19:06

技巧是:恢复 oninit 中的所有内容,并按照上次请求时保存视图状态的顺序......棘手棘手

the trick is: reinstatiate everything in oninit, and in the order as the viewstate was saved at the last request ... tricky tricky

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文