递归输出ASP.NET页面所有控件的类型和ID的代码_asp.net教程-查字典教程网
递归输出ASP.NET页面所有控件的类型和ID的代码
递归输出ASP.NET页面所有控件的类型和ID的代码
发布时间:2016-12-29 来源:查字典编辑
摘要:写一个方法:复制代码代码如下:privatevoidDisplayAllControl(Controlcontrol,intstep){fo...

写一个方法:

复制代码 代码如下:

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教程学习
    热门asp.net教程学习
    编程开发子分类