问题描述
我有一个基于一个面板
自定义控制。这只是一个简单的面板3 DropDownLists。如果我添加一个 CompareValidator
我的WebForm和的ControlToValidate
属性设置为我定制控件的ID,我得到以下错误:
I have a custom control based on a Panel
. It's merely a simple panel with 3 DropDownLists. If I add a CompareValidator
to my WebForm and set the ControlToValidate
property to the ID of my custom control I get the following error:
控制{0}由ControlToValidate属性引用{1}无法验证。
我明白为什么,在CompareValidator无法理智地验证对面板
东西。那么,我需要添加到我的自定义控制,有可能使验证程序能够验证呢?
I understand why, the CompareValidator cannot sensibly validate anything against the Panel
. So what do I need to add to my custom control to make it possible for a validator to be able to validate it?
我曾尝试添加文本
属性来我面板,返回3 DropDownLists的Text属性的组合。没有结果。
I have tried adding a Text
property to my Panel which returns a combination of the Text properties of the 3 DropDownLists. No avail.
我试图寻找某些接口( ITextControl
)的可验证的控件(文本框
)来实现,并把它们添加到我的自定义控制。没有结果。
I have tried looking for certain interfaces (ITextControl
) that validatable controls (TextBox
) implement and add them to my custom control. No avail.
我怎样才能让我的自定义控制基于一个小组,由正规.NET验证可验证? (的RequiredFieldValidator,CompareValidator等)
How can I make my custom control based on a Panel, validatable by the regular .net validators? (RequiredFieldValidator, CompareValidator, etc.)
推荐答案
如果您还没有拥有它,你需要在 ValidationProperty
属性添加到您的类,以便它知道要用于验证这些属性:
If you don't already have it, you need to add the ValidationProperty
attribute to your class so it knows which property to use for validation:
[ValidationProperty("Text")]
[ToolboxData("<{0}:YourCustomControl runat=server></{0}:YourCustomControl>")]
public class YourCustomControl : WebControl
...
这篇关于如何使一个自定义的控制可验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!