FileUpload1.HasFile is always returning false

前端 未结 3 1877
闹比i
闹比i 2021-01-14 05:34

I am uploading file using ASP.net File upload control. My FileUpload1.HasFile is always returning false.

if (FileUpload1.HasFile)
        {
            DBOpe         


        
相关标签:
3条回答
  • 2021-01-14 06:03

    ASP.NET's "AJAX" thing doesn't support file uploads in UpdatePanels out of the box. Change that trigger into a PostBackTrigger (which causes a full page load) or use something else to upload the file.

    0 讨论(0)
  • 2021-01-14 06:17

    Add a trigger for your UpdatePanel

    <Triggers> 
       <asp:PostBackTrigger ControlID="btnUploadFile" /> 
    </Triggers> 
    

    This will force a postback when the upload button is clicked.

    Also add the line below to the Page_Load

    Page.Form.Attributes.Add("enctype", "multipart/form-data"); 
    
    0 讨论(0)
  • 2021-01-14 06:20

    I know this post if old, but I found that if the file is empty [ 0 KB ] then it will return false as well. There has to be something in the file in order for .HasFile to acknowledge it.

    0 讨论(0)
提交回复
热议问题