如何从dll动态加载用户控件到asp:面板 [英] How to load a User Control dynamically from a dll into asp:panel

查看:68
本文介绍了如何从dll动态加载用户控件到asp:面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有超过3个网站。所以我想在这些应用程序中共享一些常见的用户控件。为此,我创建了一个新的Web应用程序,它具有通用的用户控件,即登录和其他一些控件。然后我使用下面的代码生成我加载到我的其他网站的ddl:



但我无法使用下面的代码将用户控件从dll加载到面板中,因为我们通过使用Control c = Page.LoadContnrol(contrlname.ascx)来完成。





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").


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

        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!

推荐答案

不,你是以错误的方式做的。如果您想开发可在其他网站/应用程序中重复使用的控件,请使用自定义控件



查看以下链接获取更多信息。

http://support.microsoft.com/kb/893667



http://oreilly.com/catalog /progaspdotnet/chapter/ch14.html
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


我的代码如下。此方法需要全名:

Assembly.GetType(字符串FullName)



my code below works. this method requires full-name:
Assembly.GetType(string FullName)

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);


这篇关于如何从dll动态加载用户控件到asp:面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆