foreach(Control ctl in this.Controls)
{
   if(ctl is Button)
    {
       Response.Write(ctl.ID+"<br>");
    }
}

解决方案 »

  1.   

    把你的控件都加在一个panel里
    然后
    private void Button1_Click(object sender, System.EventArgs e)
    {
    string IDCollection="";
    foreach(Control c in this.Panel1.Controls)
    {
      if( c is Button)
      IDCollection+=c.ID;

    }
    this.Label1.Text=IDCollection;
    }
      

  2.   

    我试了一下,老是不会走进判断里面去,也就是不走
    Response.Write(ctl.ID+"<br>");
    判断进不去,我哪里写的不合适哦,怎么没有正确地结果哦
      

  3.   

    代码在什么窗体下?
    确定this范围
      

  4.   

    刚才的方法有局限
    这个就可以了:
    private void Button1_Click(object sender, System.EventArgs e)
    {
      ControlCollection c=this.Controls;
              GetControlsID(c);
      this.Label1.Text=IDCollection;
    }
    public void GetControlsID( ControlCollection c)
    {
    foreach (Control s in c)
    {
     if(s is Button)
     IDCollection+=s.ID;
     else
     GetControlsID(s.Controls);
    } }
      

  5.   

    在一个页面里 里面的控件的组成是个树型结构 所以要用递归来求
    光是this.controls是不行的 这个ControlCollection里只有一个Form
      

  6.   

    foreach (Control c in this.Page.Controls[1].Controls)

    {
    if(c is Button)
    ((Button)c).Text="";
    }