I have an asp control to upload files.
<asp:FileUpload ID="fuAttachmentsSoporte" CssClass="required" runat="server" ClientIDMode="Static"/>
<asp:Button ID="btnAttachmentsSoporte" runat="server" Text="Adjuntar" CausesValidation="False" OnClick="btnAttachmentsSoporte_Click" disabled />
<asp:HiddenField ID="HFUploadMaxFileSize" ClientIDMode="Static" runat="server" /><br />
<asp:Label runat="server" ID="lblMensajeError" style="display:none;" CssClass="ms-formvalidation">El archivo seleccionado excede del tamaño máximo permitido.</asp:Label>
Using a javascript function, I control the size of the file, and if it is larger than desired, I indicate it to the user and I do not unblock the button to attach.
function ValidateMaxSize(fileId) {
var file = document.getElementById(fileId);
var fileSize = file.files[0].size / 1024;
var lblError = file.parentElement.children[4];
var btn = file.parentElement.children[1];
lblError.style.display = 'none';
var maxFileSize = document.getElementById("HFUploadMaxFileSize").value;
if (fileSize > maxFileSize) {
lblError.style.display = 'block';
btn.disabled = true;
return false;
}
btn.disabled = false;
return true;
}
The problem is that if I delete that file and give it to save, I get an error! and the thing is that even if you reset the input or put its value at 0 file[0]
still has value ...
Doing the same thing with a small file does not happen to me.