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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/aspnet/245952.html

猜你在找的asp.Net相关文章