简体   繁体   English

验证ASP.NET验证程序控件的客户端事件处理程序

[英]Client side event handler on validation for asp.net validator controls

I have an asp.net form with bunch of sections that can be expanded/collapsed and are normally collapsed. 我有一个asp.net表单,其中包含可以扩展/折叠和通常折叠的部分串。 Now, most controls on the form have RequiredFieldValidator or some other validators attached. 现在,表单上的大多数控件都具有RequiredFieldValidator或其他一些验证程序。 If the user tries to submit the form with required fields not filled out, for m is not submitted but because most sections are normally collapsed, the user doesn't see the validator text (like exclamation mark on the right of a text box) prompting to fix the error. 如果用户尝试提交未填写必填字段的表单,则因为未提交m,但是由于大多数部分通常都处于折叠状态,因此用户看不到验证器文本(如文本框右侧的感叹号)解决错误。 What I want to do is for the controls that fail validation, to expand their parent containers so user could see those failed controls, but for that I need to hook up some client sode javascript that woudl execute when client side validation failed. 我要为未通过验证的控件扩展它们的父容器,以便用户可以看到那些失败的控件,但是为此,我需要连接一些在客户端验证失败时执行的客户端纯JavaScript。 I haven't foudn any way of doing it - validators naturally dont' expose those "validation events" to hookup to. 我还没有办法做-验证者自然不会将那些“验证事件”暴露给连接对象。 Of course I can create my custom validators but that would mean rewriting (and duplicating functionality) completely all existing asp.net validators which sounds a big chunk of work. 当然,我可以创建我的自定义验证器,但这将意味着完全重写(和复制功能)所有现有的asp.net验证器,这听起来工作量很大。

Any ideas? 有任何想法吗?

Thank you in advance! 先感谢您! Andrey 安德烈

Here is how I solved a similar issue. 这是我解决类似问题的方法。 For every validator that is added to the accordion, I store the validator id in an array, along with the accordion panel that it is contained in. I then pass this list to the client. 对于添加到手风琴的每个验证器,我将验证器ID及其包含的手风琴面板存储在一个数组中。然后,将此列表传递给客户端。 I also hook into the OnSubmit event by calling Page.ClientScript.RegisterOnSubmitStatement. 我还通过调用Page.ClientScript.RegisterOnSubmitStatement挂接到OnSubmit事件。 The javascript function that executes during the onSubmit first checks to see if the page is valid, if so then it just exits, if not then it loops through the list of validators looking for ones that are not valid, when it finds one, it expands the section associated with that validator. 在onSubmit期间执行的javascript函数会首先检查该页面是否有效,如果是,那么它将退出,否则,它将循环遍历验证器列表,查找无效的验证器,当发现验证器时,它将展开与该验证器关联的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET 自定义验证器客户端和服务器端验证未触发 - ASP.NET Custom Validator Client side & Server Side validation not firing 使用javascript(客户端验证)更改ASP.NET自定义验证程序的错误消息? - Change error message for ASP.NET custom validator using javascript (client-side validation)? 是否可以在 asp.net 控件上进行仅客户端验证? - Is it possible to have client-side only validation on asp.net controls? ASP.NET中的验证控件是在服务器端还是在客户端运行? - Validation controls in ASP.NET are run at server- or client-side? Asp.net验证控件和服务器端验证 - Asp.net validation controls and server side validation ASP.Net Core 客户端验证:是否存在“验证成功”的 DOM 事件? - ASP.Net Core client-side validation: is there a “validation succeeded” DOM event? 如何在ASP.NET MVC的客户端中触发自定义验证器 - How to fire a custom validator in client side at ASP.NET MVC ASP.NET要求从客户端进行验证器更改 - ASP.NET required validator change from client side 可以在asp.net Webforms中同时进行客户端单击和单击事件处理程序吗? - Can have both client side click and click event handler in asp.net webforms? ASP.NET Webforms:在客户端上重新创建回发视图,而无需调用事件处理程序 - ASP.NET Webforms: Recreate a Postback View on Client-side without calling Event Handler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM