User351619809 posted
am trying to limit the number of files that can be uploaded to 2. I have the following validator and code to resolve this issue:
<asp:ValidationSummary runat="server" ID="ValidationSummary1"
DisplayMode="BulletList" ShowMessageBox="false" ShowSummary="True" CssClass="alert alert-danger" />
<asp:FileUpload runat="server" ID="UploadPDF" AllowMultiple="true" accept=".pdf" />
<asp:CustomValidator Display="None" ID="customValidatorUpload" runat="server" ErrorMessage="Only five files can be uploaded" ControlToValidate="UploadPDF" ClientValidationFunction="ValidateFile2();" />
Below is the ValidateFile2() function:
<script>
function ValidateFile2(sender, args) {
var fileCount = document.getElementById('UploadPDF').files.length;
if (fileCount > 2)
{
args.IsValid = false;
}
else if (fileCount <= 0)
{
args.IsValid = false;
}
args.IsValid = true;
}
</script>
When I try to upload more than 2 files, I dont see any error message. I am not sure what am I doing wrong.
Any help will be greatly appreciated.