每次单击按钮时,我都想创建一个新的文件上传字段。我在页面中有一个表单,我想将字段添加到该表单。我试图在会话中保存一组文件上传字段,但它似乎不起作用。
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;
}
}
}