0

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

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;
        }
    }
}
4

1 回答 1

0

必须在 Page_Init 事件中添加动态控件,请参阅我在以下帖子中的回答:

动态生成的按钮,点击时未执行

于 2012-06-15T13:08:11.503 回答