欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP.NET(C#)中遍历所有控件

程序员文章站 2024-03-08 22:53:28
复制代码 代码如下:for (int i = 0; i < this.controls.count; i++) { foreach (system.web.ui.co...
复制代码 代码如下:

for (int i = 0; i < this.controls.count; i++)
{
foreach (system.web.ui.control control in this.controls[i].controls)
{
if (control is textbox)
(control as textbox).text = "";
}
}
foreach (control cl in this.page.findcontrol("form1").controls)
{
if (cl.gettype().tostring() == "system.web.ui.webcontrols.textbox")
{
((textbox)cl).text = "";
}
}