【发布时间】:2016-01-01 20:03:19
【问题描述】:
我正在开发一个页面来管理 ASP.NET 应用程序中的权限。我想知道是否有一种方法可以轻松列出我的页面的所有控件。
此方法在下拉列表中列出所有页面:
//I take all aspx and ascx pages from my solution
foreach (String item in Directory.GetFiles(Server.MapPath("~")).
Where(key => key.EndsWith("aspx") || key.EndsWith("ascx")))
{
String[] itemSplit = item.Split('\\');
listePages.Items.Add(new ListItem(itemSplit[itemSplit.Length - 1], itemSplit[itemSplit.Length - 1]));
}
当用户选择页面时会触发此事件:
Page g = (Page)Activator.CreateInstance(Type.GetType(pageName));
foreach (Control c in g.Form.Controls)
{
this.listeControls.Items.Add(new ListItem(c.ClientID, c.ClientID));
}
但是这个事件触发了 NullReferenceException
感谢您的帮助。
【问题讨论】:
-
我没听懂你。您想从一个目录中找到所有
.aspx和.ascx文件吗?或者您是直接从解决方案中尝试这样做?