Recursively output the types of all controls on the ASP.NET page and the code for ID

  • 2020-05-16 06:47:49
  • OfStack

Write 1 method:
 
private void DisplayAllControl(Control control, int step) 
{ 
foreach (Control ctl in control.Controls) 
{ 
string s = new string('-', step * 4) + ctl.GetType().Name + " The < " + ctl.ID + " > "; 
Response.Write(s + "<br/>"); 
if (ctl.HasControls()) 
DisplayAllControl(ctl, step + 1); 
} 
} 

Call:
DisplayAllControl(this.Page, 0);
After executing this method, it outputs the types and ID values of all controls in a hierarchy on the page, even controls in GridView, master pages, and user controls.

Related articles: