0
votes

I have a repeater object that displays a number of rows. I also have a button after the repeater which allows a new repeater row to be added. The issue it that the ItemDataBound event is getting triggered before the click event. So when the page reloads it does not have the newest item that would normally show up. The only way to see the item is to refresh the page.

Code for data bound:

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, "');"));



            }
        }

and the click event

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

Is there a way to trigger the click event before the ItemDataBound?

1
"The issue it that the ItemDataBound event is getting triggered before the click event" Why do you databind the repeater on postbacks from page_load? You should do that only from event handlers(like your button-click) if at all. - Tim Schmelter
@TimSchmelter - Thanks, I added rptDetail.DataBind(); to the click event and that worked. - james31rock

1 Answers

1
votes

"The issue it that the ItemDataBound event is getting triggered before the click event"

Why do you databind the repeater on postbacks from page_load? You should do that only from event handlers like your button-click(if at all).

If EnableViewState is true (default), you don't need to databind it on every postback.