【问题标题】:control.click triggering after ItemDataBound在 ItemDataBound 之后触发 control.click
【发布时间】:2023-03-24 09:34:01
【问题描述】:

我有一个显示多行的转发器对象。我在中继器后面还有一个按钮,允许添加新的中继器行。在单击事件之前触发 ItemDataBound 事件的问题。因此,当页面重新加载时,它没有通常会显示的最新项目。查看该项目的唯一方法是刷新页面。

数据绑定代码:

protected void default_ItemDataBound(object source, RepeaterItemEventArgs e)
        {

            // Bind the controls
            if (e.Item.ItemType == ListItemType.AlternatingItem
                    || e.Item.ItemType == ListItemType.EditItem
                    || e.Item.ItemType == ListItemType.Item
                    || e.Item.ItemType == ListItemType.SelectedItem)
            {


                XElement otherStructureElement = XML.XPathSelectElement(e.Item.DataItem.ToString());

              HtmlAnchor lnkRemove = e.Item.FindControl("lnkRemoveForm") as HtmlAnchor;
              if (lnkRemove != null && otherStructureElement != null)
                  lnkRemove.Attributes.Add("onclick", string.Concat("return deleteOtherStructure('",otherStructureElement.Attribute("id").Value, "');"));



            }
        }

以及点击事件

    protected void SaveOtherStructuress_Click(object sender, EventArgs e)
    {
        AddOtherStructure();
    }

有没有办法在ItemDataBound之前触发点击事件?

【问题讨论】:

  • “ItemDataBound 事件在点击事件之前被触发的问题” 为什么要在 page_load 的回发中对转发器进行数据绑定?如果有的话,你应该只从事件处理程序(比如你的按钮单击)中这样做。
  • @TimSchmelter - 谢谢,我添加了 rptDetail.DataBind();到点击事件并且有效。

标签: c# asp.net


【解决方案1】:

"ItemDataBound 事件之前被触发的问题 点击事件”

为什么在来自page_load 的回发中对转发器进行数据绑定? 您应该仅通过按钮单击(如果有的话)之类的事件处理程序来执行此操作。

如果EnableViewStatetrue(默认),您不需要在每次回发时都对其进行数据绑定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-12
    • 2018-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-02
    • 1970-01-01
    相关资源
    最近更新 更多