【发布时间】:2012-08-28 11:07:45
【问题描述】:
给定 Web 应用程序中的这个用户控件 ascx:
<%@ Control Language="C#" Inherits="TypeX" Codebehind="TypeX.ascx.cs" %>
我开始时是否可以使用反射来获取用户控件:
Type targetType = typeof(TypeX);
... now what? to code to get the usercontrol
我试过用:
assembly.GetTypes().Where(t => t.IsSubclassOf(targetType))
但这并没有给出任何结果。
任何帮助表示赞赏
额外信息:
代码隐藏(简化)是:
public partial class TypeX : UserControlBase
{
}
//we use this control:
<%@ Control Language="C#" Inherits="Loadcontrol " Codebehind="Loadcontrol .ascx.cs" %>
//with this codebehind
public partial class Loadcontrol
{
OnPrerender()
{
string controlToLoad = "TypeX";
//what to do here
}
}
我希望现在更清楚了
更新:我制作了一个示例 web 应用程序来显示问题。 下载地址:WebApplication1.zip 或使用:Download mirror
【问题讨论】:
标签: c# asp.net reflection