Loading and displaying Web user contol assemblies?

Discussion in 'ASP .Net Building Controls' started by Carl, Oct 21, 2003.

  1. Carl

    Carl Guest

    Hi,
    I am developing a web portal where “tenants†should be able to register their own Web user controls. Basically what I need to do is to load and render the Web controls during run time. The problem is that I can’t recompile my portal application each time a new component is added so adding references to the project and using the LoadControl method is not an option.

    My current code looks something like this,

    object obj = null;
    Assembly a = null;
    Type type = null;
    string url = "Path to User Controll dllâ€
    a = System.Reflection.Assembly.LoadFile(url,null); //Load assembly
    type = a.GetType("myUserControls.theControlToLoad"); //Get type def
    obj = Activator.CreateInstance (type); //Create obj
    MethodInfo mi = type.GetMethod("InitializeAsUserControl");
    System.Web.UI.Page myPage = this;
    object[] myParametersArray = new object[1];
    myParametersArray[0]= myPage;
    mi.Invoke(obj,myParametersArray); //Call method
    System.Web.UI.UserControl myControl = (System.Web.UI.UserControl) obj; //Type cast
    this.PlaceHolder1.Controls.Add(myControl); //Add control to web page

    The problems I am having is,

    a) No UI components in the User control gets instantiated i.e. they are NULL.
    (I have been able to work around this by creating a public method that instantiates all the objects but there must be another way.)

    b) I have to override the render method in the User control. If I don’t no GUI is shown when I add the control. If possible I would like to leverage the “GUI information†captured in the .ascx file so that I don’t have to add a bunch of HTML code in my render method.

    Any help would be greatly appreciated.

    Thanks,
    Carl
     
    Carl, Oct 21, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Timothy
    Replies:
    1
    Views:
    542
    Gaurav Khanna [C# MVP]
    Jan 27, 2004
  2. Michael Gaillez

    ASP.NET and dynamically loading assemblies

    Michael Gaillez, Jun 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    404
    Oleg Ogurok
    Jun 24, 2004
  3. Barry Kelly
    Replies:
    4
    Views:
    4,791
    Barry Kelly
    Dec 7, 2004
  4. =?Utf-8?B?UmFuYQ==?=

    Loading Assemblies from a Newtwork PC - Web Application

    =?Utf-8?B?UmFuYQ==?=, Jun 10, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    377
    =?Utf-8?B?UmFuYQ==?=
    Jun 10, 2005
  5. Shree

    Cannot Get The I.E.Web Contol.Dll after Downloading

    Shree, Sep 29, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    100
    Alvin Bruney
    Sep 30, 2003
Loading...

Share This Page