Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have more than 3 websites. So I want to share some common user controls among these applications. For this purpose i have created a new web application having common user controls i.e login, and some other controls. Then i produce the ddl which i load into my other web sites using below code:

But i unable to load the user control from dll into panel using below code as we do by using Control c = Page.LoadContnrol("contrlname.ascx").


C#
Assembly assembly = Assembly.LoadFrom(pluginPath);
Type controlType = assembly.GetType("ABCCommon.controls.LoginPanel");
object controlss = Activator.CreateInstance(controlType);      

// this section doesn't load the user control from dll into page
pnlLoginControl.Controls.Add((Control)c);


or

C#
        Assembly plugin = Assembly.LoadFrom(pluginPath);

        Type[] types = plugin.GetTypes();

        foreach (Type t in types)
        {
            if (typeof(UserControl).IsAssignableFrom(t))
            {
                UserControl control = (UserControl)Activator.CreateInstance(t);

                controls.Add(control);
            }
        }

        UserControl c = (UserControl)controls[0];

// this section doesn't load the user control to page
        this.pnlLoginControl.Controls.Add(c);     


Please can anyone help?
Thanks!
Posted
Updated 26-Oct-11 0:02am
v2
Comments
Amir Mahfoozi 26-Oct-11 7:16am    
did you add a static refrence to your reference list? or even try to use that component staticly to test whether it works or not ?

No you are doing it in a wrong way. If you want to develop controls which can be reusable in other Web Sites/Applications then use "Custom Controls".

Have a look at below links for more information.
http://support.microsoft.com/kb/893667

http://oreilly.com/catalog/progaspdotnet/chapter/ch14.html
 
Share this answer
 
my code below works. this method requires full-name:
Assembly.GetType(string FullName)

C#
Assembly assembly = Assembly.Load("App_Web_mywsc.ascx.cdcab7d2");

// Display all the types contained in the specified assembly. 
foreach (Type oType in assembly.GetTypes())
{
    System.Diagnostics.Debug.WriteLine(oType.FullName);
}
Type controlType = assembly.GetType("ASP.mywsc_ascx");//fullname
object controlss = Activator.CreateInstance(controlType);
// this section doesn't load the user control from dll into page
myDIV.Controls.Add((Control)controlss);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900