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?
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.
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.
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.
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.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With