TextBox tt=new TextBox();
foreach (Control mc in Page.Controls)
{
foreach (Control cc in mc.Controls)
{
if (cc.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
{
tt = (TextBox)cc;
tt.Text = "1";
tt.ReadOnly = true;
}
}
}以后为嵌套实现:
private void test(Control c)
{
foreach (Control childControl in c.Controls)
{
if (childControl is TextBox)
((TextBox)childControl).Text = "2";
else
test(childControl);
}
}test(this.Page)
posted on
浙公网安备 33010602011771号