Question

I have an ASP.NET page with a jQuery dialog that is displayed to change some data. I am setting up the jQuery dialog so that when the user clicks the OK button it calls ASP.NET's

Page_ClientValidate('validationGroup') via javascript, finds all the invalid controls and changes their CSS class. So here's the scenario: the user opens the dialog, keys in some invalid data, clicks OK (receiving the validation messages), and then clicks Cancel.

Now the dialog is closed, but the validation messages are still there, so that when they open the dialog again, the data goes back to the way it was initially, but the form is still in the invalid state (the validation messages are still displaying).

What I need is a "reset" function of sorts to call after calling Page_ClientValidate('validationGroup'). Does this exist?

Was it helpful?

Solution

You can call the client-side function ValidatorValidate(validatorObj) to force validation to trigger again upon a specific validator. If you're resetting (clearing) the form values to what the validators are expecting as defaults, then triggering the ValidatorValidate function on them, you should be okay. See documentation here.

OTHER TIPS

Why don't you put the a from around the inputs in your dialog and use a reset button for cancel

<input type="reset" value="Cancel" />

Edit:

if your dialog control are already reset, re-validate when opening the dialog.

  1. Give your validators sequential IDs such as validator1, validator2, etc.

  2. Run the following javascript code to hide the error message:

    var n = 0;
    var z = '';
    
    for (var i = 0; i < Page_Validators.length; i++) {
        n += 1;
        z = 'ctl00_MainContent_validator' + n;
        document.getElementById(z).style.visibility = 'hidden';
    }
    

    This will loop through your validators and hide any previously displayed error messages.

  3. When a submit button is pressed, the validators will do their thing again and display the error messages again for any validation which fails.

Voila.

Why don't you just remove validation messages when user clicks cancel?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top