public static void In(Control ctl)
{
第一种方法:能找到lbTest对象
foreach (Control c in ctl.Controls)
{
if (c.ID == "lbTest")
{
Label l = c as Label;
l.Text = "hello";
}
} 第二种方法:不能找到lbTest对象
Label c = ctl.FindControl("lbTest") as Label;
if (c != null)
{
c.Text = "hello";
}
}
{
第一种方法:能找到lbTest对象
foreach (Control c in ctl.Controls)
{
if (c.ID == "lbTest")
{
Label l = c as Label;
l.Text = "hello";
}
} 第二种方法:不能找到lbTest对象
Label c = ctl.FindControl("lbTest") as Label;
if (c != null)
{
c.Text = "hello";
}
}
试试
if (c != null)
{
c.Text = "hello";
}