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:
Control '{0}' referenced by the ControlToValidate property of '{1}' cannot be validated.
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?
I have tried adding a Text
property to my Panel which returns a combination of the Text properties of the 3 DropDownLists. No avail.
I have tried looking for certain interfaces (ITextControl
) that validatable controls (TextBox
) implement and add them to my custom control. No avail.
How can I make my custom control based on a Panel, validatable by the regular .net validators? (RequiredFieldValidator, CompareValidator, etc.)
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
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With