如何使用动态生成的按钮通过动态生成的FileUpload控件上传文件?

时间:2013-03-07 14:27:43

标签: c# asp.net dynamic findcontrol dynamic-controls

如何通过动态生成的文件上传控件上传文件并单击动态生成的按钮事件?

以下是我尝试的代码,但它不起作用:

void UpLdButton_Click(object sender, EventArgs e)
{
    Button btnUpLD = sender as Button;
    btnUpLD = (Button)this.FindControl(Form.ID).FindControl(table.ID).FindControl(row.ID).FindControl(cell.ID).FindControl(UpLdButton.ID);

    fileUp = (FileUpload)this.FindControl(Form.ID).FindControl(table.ID).FindControl(row.ID).FindControl(cell.ID).FindControl(fileUp.ID);
    string args = ((Button)sender).CommandArgument;
    //lblTest.Text = args;        
    //UploadFile(fileUp);

    if (fileUp.HasFile)
    {
        fileUp.PostedFile.SaveAs(Server.MapPath("~\\") + fileUp.FileName);            
        Label1.Text = "The" + fileUp.FileName + " Has been uploaded";
    }
    else
    {
        Label1.Text = "FILE not selected";
    }
}

提前致谢!!!

0 个答案:

没有答案