递归输出ASP.NET页面所有控件的类型和ID的代码
时间:2021-07-14 07:56:46|栏目:.NET代码|点击: 次
写一个方法:
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、母版页、用户控件里的控件也不例外。
复制代码 代码如下:
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、母版页、用户控件里的控件也不例外。
上一篇:.NET Core Web APi大文件分片上传研究实现
栏 目:.NET代码
本文标题:递归输出ASP.NET页面所有控件的类型和ID的代码
本文地址:http://www.codeinn.net/misctech/157033.html






