I try to create my own capcha (ctrlCapcha :UserControl) and I would like to use validator, which will display capcha error on ValidationSummary control.
我尝试创建自己的capcha(ctrlCapcha:UserControl),我想使用验证器,它将在ValidationSummary控件上显示capcha错误。
At first I tried to create validator by inherit by BaseValidator class, but I can not pin it to my aspx file (<%@ Register %> doesn't work)
起初我尝试通过BaseValidator类继承来创建验证器,但我无法将其固定到我的aspx文件(<%@ Register%>不起作用)
At second I tried to use CustomValidator, but when I fix ID of my capcha control asp.net give me error "Control 'ctrlCapcha' referenced by the ControlToValidate property of 'cusValCapcha' cannot be validated." (I service event "OnServerValidate")
第二次我尝试使用CustomValidator,但是当我修复我的capcha控件的ID时,asp.net给出了错误“由'cusValCapcha'的ControlToValidate属性引用的控件'ctrlCapcha'无法验证。” (我服务活动“OnServerValidate”)
Could you tell me which way is better? Thank for you all suggestions :)
你能告诉我哪条路更好吗?谢谢大家的建议:)
1 个解决方案
#1
1
What are the fields that are inside the UserControl? I assume you want to validate one of these fields. You can add the Customvalidator to the UserControl itself and implement your ServerValidate inside the codebehind of the user control. You don’t have to set the “ControlToValidate” property. In the ServerValidate, you just add whether validation logic you want.
UserControl中的字段是什么?我假设您要验证其中一个字段。您可以将Customvalidator添加到UserControl本身,并在用户控件的代码隐藏中实现ServerValidate。您不必设置“ControlToValidate”属性。在ServerValidate中,您只需添加是否需要验证逻辑。
#1
1
What are the fields that are inside the UserControl? I assume you want to validate one of these fields. You can add the Customvalidator to the UserControl itself and implement your ServerValidate inside the codebehind of the user control. You don’t have to set the “ControlToValidate” property. In the ServerValidate, you just add whether validation logic you want.
UserControl中的字段是什么?我假设您要验证其中一个字段。您可以将Customvalidator添加到UserControl本身,并在用户控件的代码隐藏中实现ServerValidate。您不必设置“ControlToValidate”属性。在ServerValidate中,您只需添加是否需要验证逻辑。