Tuesday 6 April 2010

Altering the error message in a asp:CustomerValidator


I'm currently using an asp:CustomerValidator, and depending on some of the logic within the method that I'm using, I wanted to alter the error message.  So after a little playing around I found that you can access the error message through the sender param that's passed in to your validation method.  So here's the method signature which everyone will be familiar with:

public void ETAValueCheck(object sender, ServerValidateEventArgs args)
So through the sender param you can access the ErrorMessage property as follows:
((CustomValidator)sender).ErrorMessage = "This is a test";
And that's it!  It really is that easy!  Simples! 


No comments:

Post a Comment