Results 1 to 5 of 5

Thread: Loading UserControl dynamically from dll

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    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:
    1. ' Add the Page Content
    2. aPlaceholder = CType(aSkin.FindControl("content"), PlaceHolder)
    3. If Not (aPlaceholder Is Nothing) Then
    4.     Dim aPageContent As UserControl
    5.     aPageContent = CType(Me.LoadControl(aPage.Content), UserControl)
    6.     aPlaceholder.Controls.Add(aPageContent)
    7. 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
    Last edited by Patch21; Jun 2nd, 2005 at 08:46 AM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    Re: Loading Control dynamically from dll

    *bump*

    help!

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Loading UserControl dynamically from dll

    Any error messages?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    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 :/

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width