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>
Through a javascript function I control the size of the file, and if it is larger than desired, I indicate it to the user and do not unlock the attach button.
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 click save, it gives me an error! and the thing is that even if you reset the input or set its value to 0, file[0]
it still has a value...
Doing the same thing with a small file doesn't happen to me.
One way to clean up a
input
typefile
is to replace it with a clone of itself: