locked
Dynamically loading user control from dll RRS feed

  • Question

  • User-95633639 posted

    I need to dynamically load a usercontrol which is published in a dll.

    if I prepare user control in a asp.net web site and get dll by publishing the site,

    I can dynamically load the user control from dll


    hovewer if I did same thing in a asp.net web project, publish it and get dll

    the user control in dll cant be loaded dynamically


    here is the sample code:


    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    Assembly assembly = Assembly.LoadFrom(@"d:\IIOrnekWebProject.dll");
    Type[] types = assembly.GetTypes();

    foreach (Type t in types)
    {
    if (t.FullName.Contains("UCAddApp"))
    PlaceHolder1.Controls.Add(LoadControl(t, null));
    }
    }
    }


    The code is not working when IIOrnekWebProject.dll is created from web project.

    But if I use the dll from web site, the code above is working.


    How can I load user control in web project dll ?


    Thanks in advance

    Tuesday, July 21, 2009 3:35 PM

Answers

  • User-1136466523 posted

    Hi,

    You mentioned that you want to put the user control (.ascx)  in your dll. This is not the right practise, the user control actually is something on the page level, it just represents a group of controls or a part of page.

    I'm afraid that what you are talking is the custom server control, right?  To deploy the custom server control in dll, see:

     Compiling the Control into an Assembly

    http://msdn.microsoft.com/en-us/library/yhzc935f(VS.80).aspx

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2009 12:44 AM

All replies

  • User-95633639 posted

    Anyone got an idea?


    Is there a way to dynamically load a usercontrol from an assambly

    and use it in web form?

    Saturday, July 25, 2009 2:10 PM
  • User-1136466523 posted

    Hi,

    You mentioned that you want to put the user control (.ascx)  in your dll. This is not the right practise, the user control actually is something on the page level, it just represents a group of controls or a part of page.

    I'm afraid that what you are talking is the custom server control, right?  To deploy the custom server control in dll, see:

     Compiling the Control into an Assembly

    http://msdn.microsoft.com/en-us/library/yhzc935f(VS.80).aspx

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2009 12:44 AM
  • User-95633639 posted

    I am trying to develop a cms like sharepoint.

    I want users to add dynamic content like webpart but much simpler form.

    As dynamic content I can use custom server control, webparts or user control

    I chose user control because of its simplicity, just prepare it by drag and drop, no extra coding.


    I know the correct way is the custom server control but its a bit difficult to code for regular users.


    As I say before the sample code is working if I prepare the user control in a web site and get dll via publishing the site


    What is the difference between these two architecture? (dlls of web project and web site)


    Monday, July 27, 2009 5:24 AM
  • User1265733821 posted

    Hello,


    I am trying to do same thing. Did you get the solution?


    I have create a control in project and create DLL. I am trying to use DLL and trying to access control to another project.

    but getting an error Object reference ....


    Let me know if you have any idea to convert Type t = Type.GetType() and add it to page control.


    Thank you.

    Wednesday, May 26, 2010 11:42 AM
  • User623035750 posted

    Just publish the website which U created with usercontrol.ascx, dll will be created in the path U gave, refer that DLL to another web apps. Ur DLL is ready to USE.

    Congrats!!!

    Monday, October 15, 2012 5:13 AM