Custom text validation error via javascript?

I want to configure the text of an ASP.net authentication error parameter using client-side javascript. How to access it via sender, args parameters in my function?

0
source share
2 answers

All you have to do is define the callback method in the ClientValidationFunction property of the CustomValidator definition:

<asp:CustomValidator id="CustomValidator1" ... ClientValidationFunction="ClientValidationFunction" /> 

Then you can define a client-side check 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 contains a link to the validation user control - since JavaScript is dynamically typed, we can simply update its errormessage property directly:

  sender.errormessage = "This is a new validation message"; 
+3
source

This worked for me:

 var clientValidationFunction = function(sender, args) { sender.textContent = sender.innerText = sender.innerHTML = "My new error text"; // etc... }; 

I just looked at the sender object and replaced all occurrences of the current error line with a new error line.

+3
source

Source: https://habr.com/ru/post/1435749/


All Articles