<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" Text="1"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server" Text="2"></asp:TextBox>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </div>
    </formcode behindprotected void Page_Load(object sender, EventArgs e)
{
    foreach (Control control in this.Controls)
    {
        if (control is TextBox)
        {
            TextBox tb = (TextBox)control;
            tb.Text = String.Empty;
        }
    }
}

解决方案 »

  1.   

    Designer文件里面控件注册了嘛?
      

  2.   

      public void Fun(ControlCollection ControlList)
            {
                foreach (Control control in ControlList)
                {
                    if (control is TextBox)
                    {
                        TextBox tb = (TextBox)control;
                        tb.Text = String.Empty;
                        if (control.HasChildren)
                            Fun(control.Controls);
                    }
                }
            }
      

  3.   

    什么意思?什么是注册?难道要用ADD方法还是别的?
      

  4.   

    你应该要用form1.controls,里面的控件属于form1下的子控件,不属于page下的子控件,虽然你在页面中可以直接访问form1下的那些控件,因为那些控件其实定义在page类下,但是不算page的子控件,只能算孙子辈,有点绕吧,呵呵
      

  5.   

    foreach (Control item in this.Page.Controls)
                {
                    foreach (Control item1 in item.Controls)
                    {
                        if (item1 is TextBox)
                        {
                            Response.Write((item1 as TextBox).Text);
                        }
                    }
                    
                }