mat*_*con 9 c# asp.net user-controls web-applications gettype
我有一个使用usercontrols动态创建网页的Web应用程序.
在我的代码中,我有以下内容:
private void Render_Modules()
{
foreach (OnlineSystemPageCustom.OnlineSystemPageHdr.OnlineSystemPageModule item in custompage.Header.Modules)
{
if (item.ModuleCustomOrder != 99 && !item.ModuleOptional)
{
string typeName = item.ModuleInternetFile;
Type child = Type.GetType(typeName);
webonlinecustombase ctl = (webonlinecustombase)Page.LoadControl("../IPAM_Controls/webtemplatecontrols/" + child.Name.ToString() + ".ascx");
ctl.Event = Event;
ctl.custompage = custompage;
ctl.custommodule = item;
this.eventprogrammodules.Controls.Add(ctl);
}
}
}
Run Code Online (Sandbox Code Playgroud)
返回的"typeName"(示例)是:
IPAMIntranet.IPAM_Controls.webtemplatecontrols.eventorgcommittee
用户控件的命名空间如下:
namespace IPAMIntranet.IPAM_Controls
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是Type.GetType(typeName)返回null.我在这里错过了什么?
Jon*_*eet 25
Type.GetType(string)仅查找当前正在执行的程序集以及mscorlib未在字符串中指定程序集名称时.
选项:
Assembly.GetType(name)适当的程序集如果您有一个简单的方法来获取相关组件(例如,通过typeof(SomeKnownType).Assembly),那么第二个选项可能更简单.
| 归档时间: |
|
| 查看次数: |
17942 次 |
| 最近记录: |