I have the following problem:
There are many validators on the page, all of them, in addition, have checks both on the client side and on the server side. One of them has only server side validation.
Problem:
My page is published, although some client-side checks are not allowed. I think that first you need to check the client side, and when everything is in order, then it should be checked on the server side.
the code:
Js part:
var hash = { '.jpg' : 1, '.jpeg' : 1, '.bmp' : 1, '.png' : 1 }; function FileExtension(obj, args) { var file = '<%=UploadFoto_FileUpload.ClientID %>'; var re = /\..+$/i; var ext = $("#" + file).val().match(re); if (ext != undefined) { ext = ext.toLowerCase(); if (hash[ext]) { args.IsValid = true; } else { args.IsValid = false; } } else { args.IsValid = false; } } function Validator2(obj, args){ args.IsValid = true; }
part of asp.net:
<asp:CustomValidator ID="UploadFoto_FileUpload_CustomValidator1" ErrorMessage="Ext error" ClientValidationFunction="FileExtension" OnServerValidate="UploadFoto_FileUpload_CustomValidator1_ServerValidate" Display="Dynamic" runat="server" /> <asp:CustomValidator ID="UploadFoto_FileUpload_CustomValidator2" ErrorMessage="De foto is te groot (maximaal 6mb)" ClientValidationFunction="Validator2" OnServerValidate="UploadFoto_FileUpload_CustomValidator2_ServerValidate" Display="Dynamic" runat="server" /> <asp:FileUpload ID="UploadFoto_FileUpload" CssClass="uploadField" runat="server" /> <asp:ImageButton ID="Submit_ImageButton" ImageUrl="../Images/btn-verzenden.png" AlternateText="Verzenden" CssClass="verzendenBtn" OnClick="Submit_ImageButton_Click" runat="server" />
After some additional test, I found that if there is only the first of them - UploadFoto_FileUpload_CustomValidator1, then the same scenario:
when the download file is empty, then an error message is displayed and the page is not published
when the file is selected, but ext is incorrect, then an error message is displayed and the page is not published
when a file with the correct ext is selected, then the error message is not displayed, but the form is submitted, even there are other validators with errors