如何在每次单击按钮时添加新字段
本文关键字:新字段 添加 字段 按钮 单击 | 更新日期: 2023-09-27 18:37:23
我想在每次单击按钮时创建一个新的文件上传字段。我在页面中有一个表单,我想将字段添加到该表单中。我试图在会话中保存一系列文件上传字段,但它似乎有效。
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
this.Session["fileUploadArray"] = new FileUpload[5];
}
protected void Button1_Click(object sender, EventArgs e)
{
FileUpload[] flArray = ((FileUpload[])(this.Session["fileUploadArray"]));
for (int i = 0; i < flArray.Length; i++)
{
if (flArray[i] == null)
{
flArray[i] = new FileUpload();
form1.Controls.Add(flArray[i]);
this.Session["fileUploadArray"] = flArray;
return;
}
}
}
动态控件必须在Page_Init事件中添加,请参阅我在以下帖子中的答案:
动态生成的按钮,单击时未执行