Howto load a usercontrol from App_Code

M

Msdn

For the last ½ year i've been looking for a way to load my usercontrols at runtime from different pages using a standard.

I know i can reference my control in my page, but i wanted to make a class that dynamicly loaded the control and added i to my page.

Today it finally worked.

Public Sub LoadTextField(ByVal CurrentPage As Page, ByVal CurrentPlaceHolder As PlaceHolder, ByVal CurrentWidth As Integer)
Dim textfield As UserControl = CurrentPage.LoadControl("~/textfield/textfield.ascx")
Dim BoxWidthProperty As System.Reflection.PropertyInfo = textfield.GetType.GetProperty("BoxWidth")
BoxWidthProperty.SetValue(textfield, CurrentWidth, Nothing)
CurrentPlaceHolder.Controls.Add(textfield)
End Sub



Hope its usefull



Regards Keld Jakobsen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top