按下Button,创建TextBox控件:
后台代码写在Button_Click事件中(后台代码也可卸载PageLoad事件中):
protected void Button1_Click(object sender, EventArgs e)
{int i = 0;
try { i = Int16.Parse(txt_num.Text); }
catch { }
TextBox _txt;
if (i > 0)
{
for (int _i = 0; _i < i; _i++)
{
_txt = new TextBox();
_txt.Text = _i.ToString();
pnl1.Controls.Add(_txt);
}
}
}
在PageLoad中动态创建的控件可以保留操作状态而静态控件不可以