I have a FormView control in an ASP.NET 2.0 app. I've got the database storing a filename (a person's picture) in a column. I can't bind the value of the column to a fileupload control - so I'm trying to use a hidden form field. Here's what I have:
<asp:HiddenField ID="pictureLink" runat="server" Value='<%# Bind("pictureLink") %>' />
<asp:FileUpload ID="pic" runat="server" />
Code Behind:
//ItemUpdating event handler
void do_update(object sender, FormViewUpdateEventArgs e)
{
FileUpload newpic = (FileUpload)profile_edit.FindControl("pic");
if (newpic.HasFile)
{
//do a bunch of file uploading "stuff" which makes a new file name
e.Keys["pictureLink"] = new_filename;
}
}
My goal is to update the hidden form field's value to the newly updated file name so the database is properly updated.
I think I'm close - but it seems like I can't programmatically alter any of the bound data fields after-the-fact.
I've tried using javascript to change the control - but the new file name will actually be different than what they upload; which javascript can't necessarily "predict" and reliably put the correct file name into the hidden form field
Any suggestions?
Thanks