秋天是秋高气爽、秋风瑟瑟的季节。农民伯伯在辛勤地收谷,秋天的大树落下了好多树叶像翩翩起舞的蝴蝶。夕阳的金辉把绿色的林海染成金黄一片。
写一个方法:
private void DisplayAllControl(Control control, int step)
{
foreach (Control ctl in control.Controls)
{
string s = new string('-', step * 4) + ctl.GetType().Name + "〈" + ctl.ID + "〉";
Response.Write(s + "<br/>");
if (ctl.HasControls())
DisplayAllControl(ctl, step + 1);
}
}
调用:
DisplayAllControl(this.Page, 0);
执行该方法后,会在页面中分层输出所有控件的类型和ID值,即使是GridView、母版页、用户控件里的控件也不例外。
以上就是递归输出ASP.NET页面所有控件的类型和ID的代码。贪婪是最真实的贫穷,知足是最真实的财富。更多关于递归输出ASP.NET页面所有控件的类型和ID的代码请关注haodaima.com其它相关文章!