[英]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.