微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net – 我可以在服务器端调用CustomValidator方法而无需分配ControlToValidate吗?

我有来自同一组的3个RadioButton,每个radioButton都启用了它的列表框.
我想检查是否检查了radiobutton,以及是否从列表框中选择了项目.

所以我使用CustomValidator只使用服务器端方法来检查条件并触发特定的ErrorMessage.

我的问题是,我可以调用方法无法将customValidator分配给控件,因为我有3个可能的radioButtons?

谢谢,
埃迪

解决方法

It is possible to use a
CustomValidator control without
setting the ControlTovalidate
property. This is commonly done when
you are validating multiple input
controls or validating input controls
that cannot be used with validation
controls,such as the CheckBox
control. In this case,the Value
property of the arguments parameter
passed to the event handler for the
ServerValidate event and to the
client-side validation function always
contains an empty string (“”).
However,these validation functions
are still called,where appropriate,
to determine validity on both the
server and the client. To access the
value to validate,you must
programmatically reference the input
control you want to validate and then
retrieve the value from the
appropriate property
. For example,to
validate a CheckBox control on the
server,do not set the
ControlTovalidate property of the
validation control and use the
following code for the handler for the
ServerValidate event.

http://msdn.microsoft.com/en-us/library/9eee01cx%28v=VS.100%29.aspx

原文地址:https://www.jb51.cc/aspnet/245952.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐