How to trigger ASP.NET client-side validations without submit?

一曲冷凌霜 提交于 2019-12-05 15:19:41

First you need to make sure all of your validators have target controls specified using the "TargetControlID" Attribute on the validators.

Then you can set up a validation group per page and specify the group name in your next button and on the controls themselves.

If you are using regular expression validators you can choose them from this website

To Validate Client Side If you are using custom validators you can create a client function and specify it on the custom validator using the ClientValidationFunction attribute and by setting EnableclientScript = "true" on the custom validator.

Just be sure your client function has sender and args parameters.

It looks like there's a supplied JavaScript function called Page_ClientValidate which should be callable to check the validation manually from JavaScript. I haven't used it, though, so YMMV.

put all your client-side validators into the same validationgroup and with your 'next' button add the same validation group. When you click the button it will automatically trigger all the validators before it does the post-back.

as to manually triggering the validation... you might also be able to use ValidatorOnSubmit(). I remember doing this in another project but i'm having a hard time finding the code.

It seems that enabling 'SetFocusOnError' on each validator triggers the validation whenever I try to leave the field.

In short decorate your model, now Data Annotations are supported from Asp.Net 4.5 Check my Answer here..Client side webform validations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!