How to call ASP.NET client side checks without submitting?

I have a website in ASP.NET (WebForms, NOT MVC) that has a survey form divided into several slides. On each slide there is the next button, which, obviously, performs the transition (on the client side, and not back or a remote request) to the next slide.

In each slide, I have several ASP.NET controls with associated validators. I want these validators to start when I press the next button (or maybe when each input loses focus?).

I remember how ASP.NET performed client-side validation on the lost focus, but maybe I'm wrong ... (I stopped working on ASP.NET for about 3 years, so I can’t remember)

thanks

UPDATE:

It would be better to force ASP.NET to run each validator when the associated control has lost focus. I remember how ASP.NET did it (or am I sleeping? = P)

+4
source share
5 answers

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

Then you can configure the verification group on the page and specify the group name in the next button and the controls themselves.

If you use regex validators, you can select them from this website.

Checking the client side If you use custom validators, you can create a client function and specify it on the user validator using the ClientValidationFunction attribute and setting EnableclientScript = "true" in the user validator.

Just make sure your client function has sender and args options.

+3
source

There seems to be a built-in JavaScript function called Page_ClientValidate , which should be available for checking validation manually using JavaScript. However, I have not used it, therefore YMMV.

+2
source

put all your client-side validators in the same validation group and use the "next" button to add the same validation group. When you click a button, it automatically starts all validators before it performs the feedback.

to manually run validation ... you can also use ValidatorOnSubmit (). I remember how it was done in another project, but it's hard for me to find the code.

+1
source

It seems that turning on "SetFocusOnError" on each validator triggers a check when I try to leave the field.

0
source

In short, decorate your model, now data annotations are supported from Asp.Net 4.5 Check my answer here. Client side web form validation

0
source

Source: https://habr.com/ru/post/1335874/


All Articles