当前位置:编程学习 > asp >>

asp.net 实现文本框初始化实例代码详解

asp.net 遍历页面控件并对文本框初化实例代码详解

 

  1. private void ClearAllText(System.Web.UI.Control contrl)
  2.   {
  3.       int ctl_count=contrl.Controls.Count;
  4.    for (int i=0;i<ctl_count;i )
  5.    {
  6.     foreach(Control ctl in contrl.Controls[i].Controls)
  7.     {
  8.      if (ctl.HasControls())
  9.      {
  10.       ClearAllText(ctl.Parent);
  11.      }
  12.      else
  13.      {
  14.       if (ctl is TextBox)
  15.        (ctl as TextBox).Text="";
  16.      }
  17.     }
  18.    }
  19.   }

 在页面中添加一个按钮,调用此函数,参数为this.Page,如:

ClearAllText(this.Page);

以上代码仅供学习,希望对大家有帮助。

补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,