private void DisplayAllControl(Control parent, int depth)
{
foreach (Control ctrl in parent.Controls)
{
string indent = new string('-', depth * 4);
Response.Write($"{indent}{ctrl.GetType().Name}〈{ctrl.ID}〉<br/>");
if (ctrl.HasControls())
DisplayAllControl(ctrl, depth + 1);
}
}
protected void Page_Load(object sender, EventArgs e)
{
DisplayAllControl(this.Page, 0);
}
Page〈〉---- ----HtmlForm〈form1〉-------- --------LiteralControl〈〉------------ --------DropDownList〈DropDownList1〉------------ --------LiteralControl〈〉------------ --------Button〈Button1〉------------ --------Panel〈Panel1〉---------------- ------------LiteralControl〈〉---------------- ------------Label〈Label1〉----------------
ClientID、UniqueID 輸出,利於前端除錯。DebugControls() 一鍵輸出。僅適用於伺服器端控制項樹。客戶端 DOM 結構可能因 Render 行為不同(如 `Visible=false` 不輸出)。