I'm having a problem with the FileUpload control in ASP.NET. It requires two postbacks to server in order to upload the file. In other words, after I select the file and click upload the page reloads but do nothing. Then I reselect the file and click upload then it works.
In my code I put a check for FileUpload.HasFile and it always fails (return false) on the first postback.
Does anybody have any information regarding this problem?
Are you using fileupload inside update panel. Please post relevant code here
Yes I did, here's the code.
<asp:UpdatePanel ID="upDefault" runat="server" UpdateMode="Conditional"> <Triggers> <asp:PostBackTrigger ControlID="UploadButton" /> </Triggers> <ContentTemplate> <asp:FileUpload ID="HinhFU" runat="server" CssClass="largectl" ValidationGroup="UpByFile" /> <asp:RequiredFieldValidator ID="rfvFU" runat="server" ErrorMessage="*" ValidationGroup="UpByFile" ControlToValidate="HinhFU" > </asp:RequiredFieldValidator> <asp:Button runat="server" ID="UploadButton" Text="Upload" ValidationGroup="UpByFile" /> <asp:Image runat="server" ID="HinhSVImg" Width="100" Height="150" ImageUrl="" Visible="false" /> </ContentTemplate> </asp:UpdatePanel>
In the uploadbutton click I just check for HinhSV.HasFile, if yes then upload it with HinhSV.SaveAs().
simply you can use AsyncFileupload...
And for normal fileupload control in updatepanel....Check this resource...
fly2theskyIn the uploadbutton click I just check for HinhSV.HasFile
I am not sure whether its your mistake while posting! But as per your code there is a fileupload control with id HinhFU and not HinhSV.