How can I upload a file through a dynamically generated file upload control and a click on the dynamically generated button's event?
Following is the code I have tried, but it's not working:
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";
}
}
Thanks in Advance!!!