views:

13

answers:

1

Hi all, I hope you can help as i've been banging my head against the wall for a while. Long story short, I want to dynamically load UserControls with LoadControl which contain their own updatepanels, and when they're on the page, be able to trigger their updates individually via their children.

To explain better, see my extremely simplified example of my issue:

Default.aspx

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</form>

Default.aspx.vb

 IF Me.IsPostBack = False
 Dim control As Control = LoadControl("WebUserControl.ascx")
 PlaceHolder1.Controls.Add(control)
 Dim control2 As Control = LoadControl("WebUserControl.ascx")
 PlaceHolder1.Controls.Add(control2)
 Dim control3 As Control = LoadControl("WebUserControl.ascx")
 PlaceHolder1.Controls.Add(control3)
 End If

WebUserControl.ascx

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
    <%= Now.ToLongTimeString%>
    <asp:Button ID="Button1" runat="server" Text="Button" />
</ContentTemplate>

If you ran this, i would like each control to be loaded, added to the placeholder, and then when you click the button in that control, only that control trigger an update.

Instead it doesn't seem to work.

If i add the controls to the page by using the usual tags, they work fine, so the issue is somewhere in the loadControl/placeholder issue.

PLEASE HELP!

A: 

As these are dynamic controls you have to add them to the page on postbacks so you need to remove 'IF Me.IsPostBack = False' 'end if'. otherwise the controls will disappear from the page after a postback.

Does that solve your problem or what exactly isnt it working?

Dave