i'm developping a page to manage rights in an ASP.NET application. I want to know if it exists a way to list all controls of my pages easily.
This method lists all pages in a dropdownlist :
//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]));
}
And this event is triggered when the user select a page :
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));
}
But this event triggered a NullReferenceException
Thanks for your help.