简体   繁体   English

在updatepanel中动态加载用户控件

[英]Dynamically loading usercontrol in updatepanel

So I'm trying to dynamically load a usercontrol into a placeholder in another usercontrol inside a updatepanel. 因此,我试图将用户控件动态加载到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): 然后在该用户控件(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: 在弹出的usercontrol的代码背后,我有:

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

And I call this show method elsewhere with: 我在其他地方将此show方法称为:

Popup.show(new MyUserControl());

Nothing loads into the placeholder though. 占位符没有任何内容。

But in the show method I can load regular server-controls fine like this: 但是在show方法中,我可以像这样正常加载常规服务器控件:

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? 谁能向我解释为什么常规控件可以很好地加载,但我的usercontrol不能加载?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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