【问题标题】:How to add my own custom User Control inside an UpdatePanel?如何在 UpdatePanel 中添加我自己的自定义用户控件?
【发布时间】:2013-06-14 12:15:50
【问题描述】:

这是我的用户控件:

AutomezziEAttrezzature.ascx

这是asp:DropDownListOnSelectedIndexChanged 阶段调用的函数:

protected void ddCategoriaHasChanged(object sender, EventArgs e)
{
    // my asp:Panel
    categoriaCaricata.Controls.Clear();
}

我想在categoriaCaricata 面板中添加这个控件。我该怎么做?有人警告我使用DynamicControlsPlaceHolder,但不清楚它是如何工作的以及为什么。

你能给我一个聪明的例子吗?

【问题讨论】:

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


    【解决方案1】:

    如果您需要为您的 UC 分配属性并动态加载它,您应该这样做"

    这是 VB.net 代码(仅作为示例),但应该可以帮助您了解其非常基本的 UC 内容

    Dim myDatesControl As New UserControl
    myDatesControl = Page.LoadControl("~/bookingControls/ucDates.ascx")
    
            With CType(myDatesControl, controls_ucDates)
                .checkInDate = Session("nowcheckin")
                .checkOutDate = Session("nowcheckout")
                .Nights = "xxx"
                .guid = currentBookingFilter.guid
                .ExtraInfo = currentBookingFilter
            End With
    
    mypanel.controls.add(myDatesControl)
    

    如果您不需要分配动态属性,则只需手动将控件添加到面板/页面,设计时并隐藏它。您可以在需要时显示它。

    【讨论】:

      【解决方案2】:

      您可以在您的页面中注册该控件:

      <%@ Register Src="~/Controls/AutomezziEAttrezzature.ascx" TagName="Automezzi" TagPrefix="uc1" %>

      然后使用它

      <uc1:Automezzi ID="ctlAutomezzi" runat="server" />    
      

      【讨论】:

        猜你喜欢
        • 2015-01-12
        • 1970-01-01
        • 1970-01-01
        • 2022-01-09
        • 2013-05-19
        • 2012-03-07
        • 1970-01-01
        • 1970-01-01
        • 2010-10-13
        相关资源
        最近更新 更多