Hi Guys,
I have a little problem here.
I have a DetailsView control and inside there I have converted one of the fields to a template and replaced it with a FileUpload control. Now when the DetailsView is inserting data, I want to get the filename from that FileUpload control and add it in the database. Here is the code I have written in the ItemInserting Event handler of the DetailsView:
Code:
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
FileUpload imageUpload = (FileUpload)DetailsView1.FindControl("FileUpload1");
e.Values["CategoryAvatarUrl"] = imageUpload.FileName;
e.Values["AddedDate"] = DateTime.Now;
}
Now the problem is the imageUplod.FileName is returning null. It is not giving me the string that is in the FileUpload control. To test this out I first added a RequiredFieldValidator to the control. I noticed that when I add a file to the control and click Send, the string in the control disappears and the RequiredFiedValidator fires indicating I have not added a file.
I tried the same example with a textbox, but I am getting the correct value from the textbox. Can anyone help me out?
Thanks