private void button7_Click(object sender, System.EventArgs e)
{
            Control a = FindControl(this, "text3");
            if (a != null) 
{
TextBox b = (TextBox)a;
                MessageBox.Show("Hello");
}
}        public static Control FindControl(Control container, string name)
        {
            Control a = null;
            foreach (Control actrl in container.Controls)
                if (actrl.Name.ToLower() == name.ToLower())
                {
                    a = actrl;
                    break;
                }
            return a;
        }

解决方案 »

  1.   

    private void button7_Click(object sender, System.EventArgs e)
    {
                Control a = FindControl(this, "text3");
                if (a != null) 
    {
    TextBox b = (TextBox)a;
                    MessageBox.Show("Hello");
    }
    }        public static Control FindControl(Control container, string name)
            {
                Control a = null;
                foreach (Control actrl in container.Controls)
                    if (actrl.Name.ToLower() == name.ToLower())
                    {
                        a = actrl;
                        break;
                    }
                return a;
            }