I'm new to the .Net platform, and I'm stuck in extracting controls from ASPX pages since two days.
I am trying to get all controls from all .aspx pages on my website. Therefore, for this, I create a page object from the class name string that I get from my database. I already saved class names of .aspx.cs files in the database
Code in C #:
Page obj = (Page)Activator.CreateInstance(null, string ClassName).Unwrap();
The string "ClassName" is taken from the database.
Now during debugging, I see that there are controls in obj , but I get 0 in controls.count . I think this is because the controls are still not initialized .
Image 1 during debugging
:
Image 2 during debugging showing my controls 
My code is as follows.
Page obj = (Page)Activator.CreateInstance(null, string ClassName).Unwrap() List<string[]> fieldsNotInDB = GetControlCollections(obj)
This is my function to get all controls from Page obj
public List<string[]> GetControlCollections(Page p) { List<string[]> controlList = new List<string[]>(); IterateControls(p.Controls, controlList); return controlList; } public void IterateControls(System.Web.UI.ControlCollection page, List<string[]> controlList) { foreach (System.Web.UI.Control c in page) { if (c.ID != null) { string []s=new string[2]; s[0]=c.ID; s[1]=c.GetType().ToString(); controlList.Add(s); } if (c.HasControls()) { IterateControls(c.Controls, controlList); } } }
How do I get controls from my obj ?
source share