简体   繁体   中英

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:

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

I want to add this control inside that categoriaCaricata panel. How can I do it? Someone warning me about using DynamicControlsPlaceHolder , but it is not clear how it works and why.

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"

This is VB.net code (An example only), but should help you out as its pretty basic UC stuff

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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