foreach (Control control in Controls) 
            { 
                        TextBox tb = (TextBox)control;
                        tb.Text = ""; 
            }
好像这样就行了吧!
我也记得不是很清楚了!

解决方案 »

  1.   

       在我的机器上能够清除所有为 TextBox的值哦
    不过一开始control.Controls[i] is TextBox  的确为false
    多循环几次就 ok了 运行完后 所有为 TextBox的值都清除了
      

  2.   


            foreach (Control control in Controls)
            {
                for (int i = 0; i < control.Controls.Count; i++)
                {
                    if (control.Controls[i].GetType().Name.ToLower() == "textbox")
                    {
                        TextBox tb = (TextBox)control.Controls[i];
                        tb.Text = "";
                    } 
                }
            }        // 下面的方法也可以实现,但不提倡,因为try...catch...比较影响性能
            foreach (Control control in Controls)
            {
                for (int i = 0; i < control.Controls.Count; i++)
                {              
                    try
                    {
                        TextBox tb = (TextBox)control.Controls[i];
                        tb.Text = "";
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
      

  3.   

                foreach (Control cin Controls) 
                { 
                        if (c is TextBox)  //为什么这里一直为false 
                        { 
                            TextBox tb = (TextBox)c;
                            tb.Text = ""; 
                        } 
                }
    我记得这样就可以了
      

  4.   

    要递归一下才可以....
     public void EmptyTextBoxs(Control Ctrl)
            {
                if (Ctrl is TextBox)
                {
                    ((TextBox)Ctrl).Text = "";            }            foreach (Control childControl in Ctrl.Controls)
                {
                    EmptyTextBoxs(childControl);
                }
            }  
          
         }
      

  5.   

    foreach (System.Windows.Forms.Control control in this.Controls) 

    if (control is System.Windows.Forms.TextBox) 

    System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ; 
    tb.Text = String.Empty ; 

      

  6.   

    foreach (System.Windows.Forms.Control control in this.Controls) 

    if (control is System.Windows.Forms.TextBox) 

    System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ; 
    tb.Text = String.Empty ; 
      

  7.   

    强烈建议使用JSvar tb = document.getElementByTagName('input');
    for(var i = 0 ; i < tb.length ; i ++)
    {
      if(tb[i].type == text)
      {
        tb[i].value = '';  }
    }
      

  8.   

    control.Controls[i] is TextBox
    你这个能确定都是textbox类型的控件吗?
      

  9.   

    要用递归做的。Controls下的字控件如果还是一个容器的话上面的代码统统不好使。只要判断ctrl是一个容器控件,就递归。
      

  10.   

     private void test(Control c)
        {
            foreach (Control childControl in c.Controls)
            {
                if (childControl is TextBox)
                    ((TextBox)childControl).Text = "";
                else
                    test(childControl);
            }
        } 
    test(this.Page) 
      

  11.   

    要递归一下才可以.... 
    public void EmptyTextBoxs(Control Ctrl) 
            { 
                if (Ctrl is TextBox) 
                { 
                    ((TextBox)Ctrl).Text = ""; 
                }             foreach (Control childControl in Ctrl.Controls) 
                { 
                    EmptyTextBoxs(childControl); 
                } 
            }  
          
        }
      

  12.   

    好多答案 
    把textbox看做html的input不就哦了!!