简体   繁体   中英

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?

好的,我了解到我显然已经使用了LoadControl方法,但是我不太明白为什么这样做是必需的:/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM