zl程序教程

您现在的位置是:首页 >  后端

当前栏目

递归输出ASP.NET页面所有控件的类型和ID的代码

NetASP输出递归代码 类型 页面 所有
2023-06-13 09:14:32 时间
写一个方法:
复制代码代码如下:

privatevoidDisplayAllControl(Controlcontrol,intstep)
{
foreach(Controlctlincontrol.Controls)
{
strings=newstring("-",step*4)+ctl.GetType().Name+"〈"+ctl.ID+"〉";
Response.Write(s+"<br/>");
if(ctl.HasControls())
DisplayAllControl(ctl,step+1);
}
}

调用:
DisplayAllControl(this.Page,0);
执行该方法后,会在页面中分层输出所有控件的类型和ID值,即使是GridView、母版页、用户控件里的控件也不例外。