I have a page (with a repater) that loads user controls which contains update panels. I want to load the user controls dynamically when the repeater binds the items (i.e. at ItemDataBound
event).
The user controls visually load okay, but the UpdatePanels does not get updated when they are triggered (I can see async postbacks happen for the other UpdatePanels). This is because the script manager manages the update panel info between Load
and PreRender
of a page, and the repeater's ItemDataBound
event happens after that (this is from this answer). So, when I load the user controls at Page_Load
or Page_Init
, the async postback works fine.
The problem is, I won't know where to insert the user controls until repeater's ItemDataBound
event. So, is there any way to resolve this problem? Can I load the user controls at Page_Load
and have the script manager register the update panels in the control, and then place the controls at the ItemDataBound
event?
So, the code goes like this:
Page:
<asp:Repeater runat="server" ID="repeater" onitemdatabound="repeater_ItemDataBound">
<ItemTemplate>
<asp:PlaceHolder runat="server" ID="plhContent" />
</ItemTemplate>
</asp:Repeater>
Page code-behind:
protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
// dynamically insert the user control in the placeholder
var uc = LoadControl("~/UserControl.ascx");
placeHolder.Controls.Add(uc);
}