Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileUpload.hasFile is always False

I have a FileUpload control (and it's not inside an UpdatePanel) and its hasFile property is always False.

   <asp:FileUpload ID="certificateUploader" runat="server"/> 

Any thought?

like image 377
Alaa.Ali Avatar asked Mar 13 '12 11:03

Alaa.Ali


People also ask

Why FileUpload HasFile is always false?

FileUpload control requires a full PostBack. Hence when you place FileUpload control in AJAX UpdatePanel and try to upload the file asynchronously using the PostedFile property is always NULL and the HasFile property is always false.

What is importance of FileUpload control HasFile property?

The HasFile property gets a value indicating whether the FileUpload control contains a file to upload. Use this property to verify that a file to upload exists before performing operations on the file.

Which property is associated with FileUpload control?

Use the FileName property to get the name of a file on a client to upload by using the FileUpload control. The file name that this property returns does not include the path of the file on the client. The FileContent property gets a Stream object that points to a file to upload.

What is FileUpload control in asp net?

ASP.NET FileUpload control allows us to upload files to a Web Server or storage in a Web Form. The control is a part of ASP.NET controls and can be placed to a Web Form by simply dragging and dropping from Toolbox to a WebForm. The FileUpload control was introduced in ASP.NET 2.0.


1 Answers

Add a trigger for your UpdatePanel

<Triggers>    <asp:PostBackTrigger ControlID="btnCertificateUpload" /> </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"); 
like image 70
dbFrameIT Support Avatar answered Oct 04 '22 21:10

dbFrameIT Support