繁体   English   中英

如何在UpdatePanel中添加我自己的自定义用户控件?

[英]How to add my own custom User Control inside an UpdatePanel?

这是我的用户控件:

AutomezziEAttrezzature.ascx

这是在OnSelectedIndexChanged阶段由asp:DropDownList调用的函数:

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

我想将此控件添加到该categoriaCaricata面板中。 我该怎么做? 有人警告我有关使用DynamicControlsPlaceHolder ,但目前尚不清楚其工作方式以及原因。

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

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

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

然后用它

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

如果您需要为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)

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

暂无
暂无

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

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