Skip to content

Instantly share code, notes, and snippets.

@doeringp
Last active February 11, 2017 16:35
Show Gist options
  • Save doeringp/529cc6f961c936fee629c285feec0a28 to your computer and use it in GitHub Desktop.
Save doeringp/529cc6f961c936fee629c285feec0a28 to your computer and use it in GitHub Desktop.
Hook into the ASP.NET client-side validation to apply some styles to the control if the validation fails.
(function($) {
if (typeof (window.ValidatorUpdateDisplay) === "undefined" || window.ValidatorUpdateDisplay == null) {
console.warn("The ValidatorUpdateDisplay() method isn't defined. Can't inject custom validation.");
} else {
var aspUpdateDisplay = window.ValidatorUpdateDisplay;
window.ValidatorUpdateDisplay = function (n) {
var $controlToValidate = $(document.getElementById(n.controltovalidate));
if (n.isvalid) {
$controlToValidate.removeClass("invalid");
} else {
$controlToValidate.addClass("invalid");
}
// Call the original ValidatorUpdateDisplay()-method.
aspUpdateDisplay(n);
};
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment