0

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);
}
Community
  • 1
  • 1
William Niu
  • 15,798
  • 7
  • 53
  • 93
  • seems like you would have to use something like (but not sure) which is why i am just commenting 'protected void Page_LoadComplete(object sender, EventArgs e)' – user710502 Mar 29 '12 at 07:13
  • could you please elaborate on how that would be helpful? – William Niu Mar 29 '12 at 07:17
  • Well, I just thought.. that it seems you need to have all things loaded in the Page_Load, so at Page_LoadComplete you can load the control and position it since all the other controls would have loaded. This is just a hypothesis.. I might be wrong – user710502 Mar 29 '12 at 07:23

0 Answers0