asp.net 初始化文本框的小例子

 更新时间:2021年9月22日 10:14  点击:1469
复制代码 代码如下:

private void ClearAllText(System.Web.UI.Control contrl)
  {
      int ctl_count=contrl.Controls.Count;
   for (int i=0;i<ctl_count;i )
   {
    foreach(Control ctl in contrl.Controls[i].Controls)
    {
     if (ctl.HasControls())
     {
      ClearAllText(ctl.Parent);
     }
     else
     {
      if (ctl is TextBox)
       (ctl as TextBox).Text="";
     }
    }
   }
  }

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

ClearAllText(this.Page);

以上代码仅供学习,希望对大家有帮助。
[!--infotagslink--]

相关文章