I want to set ASP.net custom validator error parameter text through client side javascript. How can access it via sender, args parameters in my function?
+1
A:
All you need to do is define the callback method in the ClientValidationFunction property of the CustomValidator definition:
<asp:CustomValidator id="CustomValidator1"
...
ClientValidationFunction="ClientValidationFunction" />
You can then define a client side validation script:
<script language="javascript">
function ClientValidationFunction(sender, args){
var valid = false;
// Validation logic..
sender.errormessage = "Validation failed";
args.IsValid = valid;
return;
}
</script>
Update: The sender variable holds a reference to the custom validator control - because JavaScript is dynamically typed, we can just update its errormessage
property directly:
sender.errormessage = "This is a new validation message";
Dexter
2010-10-25 06:56:26
Thanks Dexter, I want to know how to set the validator's error message parameter throught javascript.
Popo
2010-10-25 07:03:09
Sure - see my edit above.
Dexter
2010-10-25 07:10:07
what is 'source' in your example ?
Popo
2010-10-25 07:34:42
Sorry - it should be `sender`
Dexter
2010-10-25 08:32:13
Thank you Dexter.
Popo
2010-10-25 09:27:05