请问怎样在页面上保存一个动态生成的控件
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
for(int i = 0; i < 3; i ++)
{
TextBox txt = new TextBox();
txt.ID = "txt" + i;
this.Panel1.Controls.Add(txt);
}
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
string str = "";
for(int i = 0; i < 3; i ++)
{
TextBox txt = (TextBox)Panel1.FindControl("txt" + i);
str += "第" + i.ToString() + "个文本框的值为:" + txt.Text + "<br>";
}
this.Label1.Text = str;
}
如上程序,在页面第一次打开时生成三个 TextBox,然后点击按钮后在Label中显示三个文本框的值,可每次在我点击按钮后那三个 TextBox就没有了,要怎么才能在页面上保存这些动态生成的控件,或有什么别的变通的方法?多谢!