Dynde
Dynde

Reputation: 2674

Dynamically loading usercontrol in updatepanel

So I'm trying to dynamically load a usercontrol into a placeholder in another usercontrol inside a updatepanel.

basically I've got this markup:

<asp:UpdatePanel ID="upPopup" runat="server">
    <ContentTemplate>
        <UC:Popup runat="server" ID="UC_Popup" />
    </ContentTemplate>
</asp:UpdatePanel>

And then this markup inside that usercontrol (Popup):

<div id="modal">
    <asp:PlaceHolder ID="phPopupPlaceholder" runat="server"></asp:PlaceHolder>
    <asp:Label ID="lblModal" runat="server"></asp:Label>
</div>

In the codebehind of the popup usercontrol I have:

public void Show(UserControl control) {
    this.phPopupPlaceholder.Controls.Add(control);
    this.lblModal.Text = "Loaded";
}

And I call this show method elsewhere with:

Popup.show(new MyUserControl());

Nothing loads into the placeholder though.

But in the show method I can load regular server-controls fine like this:

this.phPopupPlaceholder.Controls.Add(new Label(){ Text = "Label!" });

Can anyone explain to me why regular controls are loaded fine, but my usercontrol isn't loaded?

Upvotes: 1

Views: 1994

Answers (1)

Dynde
Dynde

Reputation: 2674

Okay, I learned that I HAVE to use LoadControl method apparently, but I don't quite understand why this is necessary :/

Upvotes: 1

Related Questions