Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivilent Loadcontrol

Tags:

vb.net

ascx

I have a .ascx file that I can load in no problem using

<uc1:EL ID="EL1" BusinessID="8" runat="server" />

Where BusinessID is a Public Property.

Public Property BusinessID As Integer
    Set(ByVal value As Integer)
        _BusinessID = value
    End Set
    Get
        Return _BusinessID
    End Get
End Property

I may need to load this ascx file several times into a placeholder with different BusinessID variable values.

What is the equivalent LoadControl way of doing so?

like image 893
Mark Cooney Avatar asked Mar 22 '26 03:03

Mark Cooney


1 Answers

First, you need to create an instance of the user control, then get a handle on the place holder. Then you can add one to the other. Example:

 'get place holder
 Dim getPh As New PlaceHolder
 getPh = CType(Me.FindControl("myPlaceHolder"), PlaceHolder)

 'get user controls    
 Dim newUserControl As New user_controls_myControlName
 newUserControl = CType(LoadControl("~/user_controls/myControlName.ascx"), user_controls_myControlName)    

 getPh.Controls.Add(newPortlet)

Once you create an instance of the user control, you have access to all its properties, including BusinessID and you can assign it whatever you want.

Forgot one thing, you will need to add a reference in the client side code of your ascx file, like this:

<%@ Reference Control="~/user_controls/myControlName.ascx"%>
like image 101
jason Avatar answered Mar 23 '26 15:03

jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!