I have a custom validator that reads a listbox and determines if the ControlToValidate, which is a textbox, contains the same string as at least one element in the listbox. My validator is not firing. I have an alert to check if it does, and it never shows up. I have the proper key in my Web.Config for my validators as well. Validator:
<asp:CustomValidator ID="alreadyRegValidator"
runat="server"
ControlToValidate="txbClassNum"
ErrorMessage="Not Removed. Course is registered for."
ClientValidationFunction="reg_validator"
Display="Dynamic"
CssClass="warning" />
Function:
<script type="text/javascript" language="javascript">
function reg_validator(source, args) {
let toRemove = args.value.toUpperCase();
let removable = true;
for (let i = 0; i < document.getElementById("lbxRegisteredClasses").children.length; i++) {
let li = document.getElementById("lbxRegisteredClasses").children[i].value;
let tokens = li.Text.split('-');
if (tokens[0].toUpperCase() === toRemove) {
removable = false;
break;
}
}
args.IsValid = removable;
alert('test');
}
</script>
I have tried everything from rebuilding my project to copying the Microsoft .NET API to a T.