【发布时间】:2015-07-03 16:45:18
【问题描述】:
我有超过 3 个网站。所以我想在这些应用程序之间共享一些常见的用户控件。为此,我创建了一个具有通用用户控件(即登录)和其他一些控件的新 Web 应用程序。然后我使用下面的代码生成我加载到我的其他网站的 ddl:
但我无法像 using Control c = Page.LoadContnrol("contrlname.ascx") 那样使用下面的代码将用户控件从 dll 加载到面板中。
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 panel
pnlLoginControl.Controls.Add((Control)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];
//此部分不会将用户控件从dll加载到面板中
this.pnlLoginControl.Controls.Add(c);
请问有人可以帮忙吗? 谢谢!
【问题讨论】: