I have a CustomValidator that is validating a telephone number for several different telephone numbering schemes. The client-side javascript looks like this:
I think the problem is that there is no 'errormessage' property on the client side. The custom validator renders a <span>
tag to display the error message with an id corresponding the id property of the custom validator control. To set the text displayed when validation fails you need to do somthing like this.
...
case "North America":
args.IsValid = validateNAPhoneNumber(cleanNumber);
if (!args.IsValid)
document.getElementById(sender.id).innerText = "* Not a NA Phone #";
break;
...
function dateofbirth(sender, args) {
var dtcDOB = document.getElementById('<%= dtcDOB.ClientID %>');
var dob = new Date(dtcDOB.value);
var currDate = new Date();
if (dtcDOB.value == "") {
args.IsValid = false;
sender.textContent = "Provide DOB.";
return;
}
args.IsValid = true;
}
Try sender.textContent = "your err msg"
.
It worked for me.
Expanding @Andy response, using jQuery:
Change the text message (show in the form):
$('#<%=this.[Validator].ClientID%>').text('Text to show');
Change the error message (for the Summary control):
$('#<%=this.[Validator].ClientID%>').attr('errormessage', 'Text to show');
Replace [Validator]
for your validator's name.