admin管理员组文章数量:1321821
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?
- possible duplicate of Reset an asp validation control via javascript? – Liam Commented Nov 1, 2013 at 13:08
4 Answers
Reset to default 2You 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.
Give your validators sequential IDs such as validator1, validator2, etc.
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.
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?
本文标签: javascriptASPNET How to quotresetquot validation after calling PageClientValidateStack Overflow
版权声明:本文标题:javascript - ASP.NET: How to "reset" validation after calling Page_ClientValidate - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742104856a2420971.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论