jeudi 5 février 2015

Javascript Custom Validator: duplicate error message


I've got a custom validator on a file upload that checks the file size. The validation works correctly, and it displays the error message in the validation summary like its supposed to, but it also displays it next to the upload control itself. Further, this error message never goes away, even if the upload control is valid:


Inline error message shouldn't be there Even after I resolve the issue, the inline error is still there I'm not sure how the inline error message is getting there, or how to get rid of it. Here's my control:



<div class="tblCell" id="celUpl6">
<asp:FileUpload ID="uplCollection6" runat="server" ClientIDMode="Static" CssClass="formfield" />
<a onclick="clearFileInputField('celUpl6')" href="javascript:noAction();" class=" linkButton">REMOVE</a>
<asp:CustomValidator ID="cvUpl6" runat="server"
ErrorMessage="- Too big!"
ControlToValidate="uplCollection6"
Display="Static"
ClientValidationFunction="validateFileSize6" ValidationGroup="vgRegForm"></asp:CustomValidator>


And here are my validation functions:



<script type="text/javascript">
function WebForm_OnSubmit() {
if (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) {
for (var i in Page_Validators) {
try {
var control = document.getElementById(Page_Validators[i].controltovalidate);
if (!Page_Validators[i].isvalid) {
control.className = " validator-controls-error";
} else {
control.className = "formfield";
}
} catch (e) { }
}
return false;
}
return true;
}



function getFileSize(uploaderName) {
if (window.ActiveXObject) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var filepath = document.getElementById(uploaderName).value;
var thefile = fso.getFile(filepath);
var sizeinbytes = thefile.size;
} else {
var sizeinbytes = document.getElementById(uploaderName).files[0].size;
}

return sizeinbytes;


}



function validateFileSize6(source, arguments) {
arguments.IsValid = (getFileSize("uplCollection6") <= sizeLimit);


}


Any insight would be greatly appreciated.


Thanks,


Jesse





Aucun commentaire:

Enregistrer un commentaire