A
A
Anatoliy Mikhailov2014-12-09 06:39:58
ASP.NET
Anatoliy Mikhailov, 2014-12-09 06:39:58

How to change client validation behavior in ASP.NET Web.Forms?

You need to change the behavior of client-side validation - namely, add the class "error" to the parent element of the field and to the container of these fields.
Project on asp.net webforms (framework version 4.5) Added the Microsoft.AspNet.ScriptManager.WebForms.5.0.0
package to the project Added the line to the ScriptManager

<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />

Judging by the documentation, when specifying the Path attribute, ScriptManager will load the requested script at the specified path instead of the assembly.
But in my project, he loaded it from the assembly ...
This article describes the work of ScriptManager'a, where it is indicated that in 3.5 some controls load validation scripts bypassing the ScriptManager and as a result the modified script will not be loaded.
Although it says "some" controls, in my project all controls bypass the ScriptManager during validation, while other scripts load normally.
Many advise to override validation functions on page load
$(function(){
        if (typeof ValidatorUpdateDisplay != 'undefined') {
            var originalValidatorUpdateDisplay = ValidatorUpdateDisplay;

            ValidatorUpdateDisplay = function (val) {
                if (!val.isvalid) {
                    $("#" + val.controltovalidate).css("border", "2px solid red");
                }

                originalValidatorUpdateDisplay(val);
            }
        }
    });

But this code doesn't always work because ScriptManager loads them dynamically
Or am I doing something wrong?
As a backup plan, you can simply make your own validators by inheriting the standard ones...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question