2

i would like to have an event fired in jquery, if the validators of my page change their states.

This is my usecase:

  1. In an Adressform the Validators all are hidden.
  2. If i submit the form, the get displayed.
  3. Now i want to fire a jQuery function, which renders all rows (not the inputfields, but their parents) with a red border (means add a css class)
  4. if i now change the field and the validator hides i also want to hide the border around the input's parent

i don't want to have a timer checking every 100ms the displayed validators (which would work perfectly), but i want to listen only to the show/hide events of the validators

any ideas, how i can add a listener to the change events of a validator?

regards Christoph

3 Answers 3

1

Here is how you can call .NET validators from JavaScript:
Manually calling ASP.NET Validation with JavaScript

You could integrate the above with jQuery events or jQuery Validation.

NOTE: This solution is if you are tied to .NET Validators, otherwise just use jQuery Validation as Dave mentioned.

Sign up to request clarification or add additional context in comments.

1 Comment

as i wanted to keep the asp.net validation working i used the method from your Link (add a functzion to the buttons click event, call the Page_ClientValidate ans check the validators on the page) Thank you for the hint.
0

Have you looked into the standard jQuery validator plugin? I'm pretty sure its validators have events you can hook into in just the way you describe.

1 Comment

I wanted a event from the asp.net validators to jquery, not the other direction.
0

Sorry for answering this old question, but I made a blog post about modifying the default javacscript evaluation function of the ASP.NET validators. Basically it comes down to this:

for (var i = 0; i < window.Page_Validators.length; i++) {
    // Create a new property and assign the original evaluation function to it
    window.Page_Validators[i].baseEvaluationFunction = window.Page_Validators[i].evaluationfunction;

    // Set our own validation function
    window.Page_Validators[i].evaluationfunction = evaluateField;
}

Next, in the 'evaluateField' function, write the code to set the css.

function evaluateField (validator) {
    // Run the original validation function
    var isvalid = validator.baseEvaluationFunction(validator);

    // Handle the result
    if (isvalid) {
        clearError(validator);
    } else {
        setError(validator);
    }

    // Return result
    return isvalid;
}

In the setError and clearError functions you can use jquery to find the parent row and apply css to it. Hope this helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.