【问题标题】:Dynamically loading usercontrol in updatepanel在更新面板中动态加载用户控件
【发布时间】:2011-02-16 11:50:37
【问题描述】:

所以我试图将用户控件动态加载到更新面板内另一个用户控件的占位符中。

基本上我有这个标记:

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

然后该用户控件(弹出窗口)中的这个标记:

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

在弹出用户控件的代码隐藏中,我有:

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

我在其他地方将此显示方法称为:

Popup.show(new MyUserControl());

虽然没有加载到占位符中。

但在 show 方法中,我可以像这样加载常规服务器控件:

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

谁能向我解释为什么常规控件加载正常,但我的用户控件没有加载?

【问题讨论】:

    标签: c# asp.net user-controls updatepanel


    【解决方案1】:

    好的,我知道我显然必须使用 LoadControl 方法,但我不太明白为什么这是必要的:/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 2011-08-01
      • 2013-12-26
      • 2018-09-08
      • 1970-01-01
      • 2015-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多