Loading UserControl dynamically from dll
Hi guys
I'm trying to load up a control from a dll dynamically onto my form, but i cannot seem to get it right. Here is some of the codebehind of my form:
VB Code:
' Add the Page Content
aPlaceholder = CType(aSkin.FindControl("content"), PlaceHolder)
If Not (aPlaceholder Is Nothing) Then
Dim aPageContent As UserControl
aPageContent = CType(Me.LoadControl(aPage.Content), UserControl)
aPlaceholder.Controls.Add(aPageContent)
End If
Now the usual way to go about this is to use this LoadControl(VirtualPath) method, and put the usercontrol's virtualpath in the parameter (this value sits in aPage.Content). My problem however, is that this usercontrol exists in another project that has been compiled into a dll and added as a reference to the current project. How can I load up this control??? It does not have a virtual path does it, as it is in the dll?
I could always instantiate this control (which works fine), but then I don't get the graphical elements do I ?
I dont know if i'm missing something small here.
Anybody have any ideas?
Thanks
Patch
Re: Loading Control dynamically from dll
Re: Loading UserControl dynamically from dll
Re: Loading UserControl dynamically from dll
Thing is is that's pointless to run the project as I do not know what to put in as the parameter for Me.LoadControl(), as the usercontrol sits in the dll, and thus there is no virtual path to the actual control.
I've been doing a little reading, and it looks like the only way I can get hold of the control is to create an instance of it. The dll does not contain the .ascx file so there are no graphical elements with it, which is useless for me as I want to load the entire control (html + codebehind). In otherwords, usercontrols cannot be shared among applications, according to this link:
http://msdn.microsoft.com/library/de...ebcontrols.asp
...and so either a copy of the control needs to be put into each application, or i'll have to use something else, like custom controls.
Oh well :/
Re: Loading UserControl dynamically from dll
You're out of luck.
A UserControl is compiled dynamically...loading its template from a path - normally the same virtual folder as the assembly.
Unless you can get access to the virtual path for where the template exists, or copy its contents to your project where it may be out of sync if someone updates the original template location. At best, its horrible design practice.
A control derived from WebControl would be your best bet.