I have a detailed view in which there is a field for downloading files. When I fill in the information and upload the file (I tried several files from 9k to 6.8MB), all the information (text fields) is transmitted in order, but the downloaded file always returns false when I check HasFile and always returns String.Empty when I check file name.
Am I doing something wrong? The type of information is in the panel and Not the update panel
<asp:Panel ID="pnlUpdate" runat="server" Visible="false"> <h4 runat="server" id="h2SubCaption">Person Details</h4> <asp:DetailsView ID="dvAssignment" runat="server" AutoGenerateRows="false" Width="100%" SkinID="SampleDetailsView" CssSelectorClass="PrettyDetailsView" DataKeyNames="guidMemberId" DefaultMode="Edit" OnItemUpdating="dvAssignment_ItemUpdating" OnModeChanging="dvAssignment_ModeChanging" AutoGenerateEditButton="True" > <Fields> <asp:TemplateField HeaderText="Nomination Letter"> <EditItemTemplate> <asp:FileUpload runat="server" ID="fileuploadNomination" /> </EditItemTemplate> </asp:TemplateField> .....
Code for:
FileUpload _nomination = (FileUpload)dv.FindControl("fileuploadNomination"); byte[] nominationByte = null; if (_nomination.FileName != string.Empty) nominationByte = _nomination.FileBytes;
EDIT I added a call to Page_Load and it looks like the page is being sent back when I click the Auto Generated Update button for the DetailsView element. This postback probably clears the FileUpload field. Any ideas on how to get around this?
Edit # 2 Now I placed the update panel around the DetailsView and set the feedback trigger in the DetailsView (see below), and it still does not work, it seems that clearing the download control has been sent earlier.
<asp:UpdatePanel ID="updatePnl" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Panel ID="pnlUpdate" runat="server" Visible="false"> <h4 runat="server" id="h2SubCaption">Person Details</h4> <asp:DetailsView ID="dvAssignment" runat="server" AutoGenerateRows="false" Width="100%" SkinID="SampleDetailsView" CssSelectorClass="PrettyDetailsView" DataKeyNames="guidMemberId" DefaultMode="Edit" OnItemUpdating="dvAssignment_ItemUpdating" OnModeChanging="dvAssignment_ModeChanging" AutoGenerateEditButton="True" > <FieldHeaderStyle Font-Bold="True" Width="150px" /> <Fields>
<asp:FileUpload runat="server" ID="fileuploadNomination" /> </EditItemTemplate> </asp:TemplateField> </Fields> </asp:DetailsView > </asp:Panel> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="dvAssignment" /> </Triggers> </asp:UpdatePanel>
Gridview code on request
<asp:GridView ID="gvQuality" runat="server" AutoGenerateColumns="False" Width="100%" DataKeyNames="guidMemberId" CssSelectorClass="PrettyGridView" SkinID="SampleGridView" OnSelectedIndexChanged="gvQuality_SelectedIndexChanged" onrowdatabound="gvQuality_RowDataBound"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="btnViewDetails" runat="server" Text="Edit" CommandName="Select" /> </ItemTemplate> </asp:TemplateField>
after that several related fields (first name, last name, etc.)
protected void gvQuality_SelectedIndexChanged(object sender, EventArgs e) { Guid guidMemberId = (Guid)gvQuality.SelectedDataKey.Values["guidMemberId"]; PortalDataContext db = new PortalDataContext(AuthenticatedUser.ConnectionString); h2SubCaption.InnerText = "Update Person"; dvAssignment.ChangeMode(DetailsViewMode.Edit); dvAssignment.DataSource = LINQ Query Here dvAssignment.DataBind(); }