利用FindControl()吧,再造型,你动态生成,编译器不能预知,所以在代码行里不能直接引用其定义的名,只能用FindControl然后再造型成Label赋值

解决方案 »

  1.   

    AddLabel当然未定义,它只在addControls方法的作用域中被定义的。private Lable m_lblAdded;private void AddControls()
          {
           m_lblAdded=new Lable();
           Controls.Add(m_lblAdded);      }
      

  2.   

    asp.net中Label myLabel = (Label)(FindControl("AddLabel"));还有,你的label为什么一定要声明在函数里面呢?
      

  3.   

    foreach (Control c in Controls)
    {
      if (c.GetType() == "System.Windows.Forms.Label")
      {
         Label l = (Label)c;
         if (l.Text == "your lable's test")
         {
           // add code here;
           break;
         }
      }
    }