[英]How to add my own custom User Control inside an UpdatePanel?
This is my User Control: 这是我的用户控件:
AutomezziEAttrezzature.ascx
and this is the function called by an asp:DropDownList
at OnSelectedIndexChanged
stage: 这是在
OnSelectedIndexChanged
阶段由asp:DropDownList
调用的函数:
protected void ddCategoriaHasChanged(object sender, EventArgs e)
{
// my asp:Panel
categoriaCaricata.Controls.Clear();
}
I want to add this control inside that categoriaCaricata
panel. 我想将此控件添加到该
categoriaCaricata
面板中。 How can I do it? 我该怎么做? Someone warning me about using
DynamicControlsPlaceHolder
, but it is not clear how it works and why. 有人警告我有关使用
DynamicControlsPlaceHolder
,但目前尚不清楚其工作方式以及原因。
Can you give to me a smart example? 你能给我一个聪明的例子吗?
You can register the control in your page: 您可以在页面中注册控件:
<%@ Register Src="~/Controls/AutomezziEAttrezzature.ascx" TagName="Automezzi" TagPrefix="uc1" %>
and then use it 然后用它
<uc1:Automezzi ID="ctlAutomezzi" runat="server" />
If you need to assign properties to your UC, and load it dynamically, you should do somwthing like this" 如果您需要为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)
If you don't need to assign dynamic properties, then just add your control to the panel/page manually, design time, and hide it. 如果不需要分配动态属性,则只需将控件手动添加到面板/页面中,设计时间,然后将其隐藏即可。 The you can show it when you need to.
您可以在需要时显示它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.