[RESOLVED] FileUpload control don't work on first submission

Hi,

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?

Thanks.

Q

Are you using fileupload inside update panel. Please post relevant code here

Nikhil,

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().

Thanks.

Q

fly2thesky

In 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.Innocent

thoughts on "[RESOLVED] FileUpload control don't work on first submission"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>