I have DetailsView with users Info (Name, Email, Picture). That DetailsView control can be edited. Values are from DataBase
protected void DVUserInfoShow_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
FileUpload EditAvatar = (FileUpload)DVUserInfoShow.FindControl("EditAvatar");
if (EditAvatar.HasFile)
{
string image_path = "~/images/user_images/" + EditAvatar.FileName;
EditAvatar.SaveAs(Server.MapPath(image_path));
e.NewValues["Avatar"] = EditAvatar.FileName;
}
else
{
e.NewValues["Avatar"] = e.OldValues["Avatar"];
}
}
The problem is with e.NewValues["Avatar"] = e.OldValues["Avatar"];, when user updates his name and email, the picture value is set to null. And that code doesn't work. What I'm doing wrong?