如何在不提交的情况下触发ASP.NET客户端验证? [英] How to trigger ASP.NET client-side validations without submit?

查看:96
本文介绍了如何在不提交的情况下触发ASP.NET客户端验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET中有一个网站(WebForms, MVC),该网站的调查表分为几张幻灯片.每张幻灯片都有一个下一个按钮,显然可以进行下一个幻灯片的转换(客户端,而不是发回或远程请求).

I have a website in ASP.NET (WebForms, NOT MVC) which has a survey form divided in several slides. Each slide has a next button that, obviously does a transition (client-side, not post back or remote request) to the next slide.

在每张幻灯片中,我都有几个ASP.NET控件及其相关的验证器.我希望在单击下一步按钮时触发该验证器(或者当每个输入失去焦点时触发).

In each slide I have several ASP.NET controls with their related validators. I want this validators to be triggered when I click the next button (or maybe when each input loses focus?).

我记得ASP.NET在失去重点的情况下进行客户端验证,但是也许我错了……(我退出ASP.NET开发大约3年了,所以我不记得了)

I remembered ASP.NET doing client side validation on lost focus, but maybe I'm wrong... (I quit doing ASP.NET development about 3 years now, so I can't remember)

谢谢

更新:

当关联的控件失去焦点时,最好使ASP.NET触发每个验证器.我记得ASP.NET这样做(或者我在做梦吗?= P)

It would be better to make ASP.NET trigger each validator when the associated control lost focus. I remember ASP.NET doing this (or am I dreaming? =P)

推荐答案

首先,您需要确保所有验证器都有使用验证器上的"TargetControlID"属性指定的目标控件.

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

验证客户端 如果使用的是自定义验证器,则可以创建一个客户端函数,并使用ClientValidationFunction属性并在自定义验证器上将EnableclientScript ="true"设置在自定义验证器上.

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.

请确保您的客户端函数具有sender和args参数.

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

这篇关于如何在不提交的情况下触发ASP.NET客户端验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆