I need to loop through all the controls in my asp.net webpage and do something to the control. In one instance I\'m making a giant string out of the page and emailing it to
Even though this question has been discussed for more than 9 years, here I leave the code that worked for me based on @Jagadheesh Venkatesan's code.
private List getControls()
{
List lControls = new List();
foreach (Control oControl in Page.Controls)
foreach (Control childControl1 in oControl.Controls)
foreach (Control childControl2 in childControl1.Controls)
foreach (Control childControl3 in childControl2.Controls)
if (childControl3.GetType().ToString().Contains("System.Web.UI.WebControls"))
lControls.Add(childControl3);
return lControls;
}