最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ASP.NET: How to "reset" validation after calling Page_ClientValidate - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Jan 13, 2010 at 18:11 David Basarab 73.4k43 gold badges130 silver badges157 bronze badges asked Jan 13, 2010 at 17:57 Josh YoungJosh Young 1591 gold badge2 silver badges10 bronze badges 1
  • possible duplicate of Reset an asp validation control via javascript? – Liam Commented Nov 1, 2013 at 13:08
Add a ment  | 

4 Answers 4

Reset to default 2

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.

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?

发布评论

评论列表(0)

  1. 暂无评论