如何验证两组控制1按钮和一个验证组? [英] How to validate two groups of controls with 1 button and a validation group?

查看:145
本文介绍了如何验证两组控制1按钮和一个验证组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组3 asp.net文本框和一组2 asp.net列表框。有一个asp.net按钮。每个列表框有一个asp.net必填字段校验器连接到​​他们。第一组中的其他3文本框不具有任何验证。当点击该按钮时,其应显示一条消息,如果任一列表框的任何选择,但不具有,如果第一组中的文本框的一个具有一定价值,那么它不应该,如果列表框具有任何值无关紧要(S )来选择。我分配的ValidationGroup vgFirst到组文本框和所述的ValidationGroup vgSecond两个列表框。然后,我分配的ValidationGroup vgSecond每个的RequiredFieldValidator和分配的按钮vgSecond的ValidatonGroup。我觉得我拥有一切权利,但我不知道如何只用一个按钮处理。我必须禁用验证的列表框如果文本框文本改变?这是我唯一的选择吗?

I have one group of 3 asp.net textboxes and one group of 2 asp.net listboxes. There is one asp.net button. The listboxes each have an asp.net required field validator tied to them. The other 3 textboxes in the first group do not have any validation. When the button is clicked, it should display a message if either of the listboxes does not have anything selected, however, if one of the textboxes in the first group has some value, then it should not matter if the listboxes have any value(s) selected. I assigned the ValidationGroup vgFirst to the group of textboxes and the ValidationGroup vgSecond to the two listboxes. I then assigned the ValidationGroup vgSecond to each RequiredFieldValidator and assigned the button a ValidatonGroup of vgSecond. I think I have everything right, but I am not sure how to handle it with just one button. Do I have to disable Validation for the listboxes if the text in the textboxes change? Is this my only option?

推荐答案

Unforuntately的的RequiredFieldValidator是不是足够聪明,可以使用这种方式。我建议你​​使用一个CustomFieldValidator,写自己的JavaScript验证或使用服务器端验证方案(这或许应该无论如何做,因为我觉得它比获取自动生成的客户端的东西更可靠一点)

Unforuntately, the RequiredFieldValidator isn't smart enough to be used that way. I suggest you use a CustomFieldValidator and write your own JavaScript validation or make use of a server-side validation scheme (which should probably be done anyway as I find it to be a bit more reliable than the client-side stuff that gets automatically generated).

编辑 -
是的......你会需要根据您是否要继续使用RequireFieldValidators在文本框的值启用/禁用验证。

edit--- Yes... you will need to enable/disable validation depending on values in your textboxes if you want to continue to use RequireFieldValidators.

这篇关于如何验证两组控制1按钮和一个验证组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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