How to make custom control valid?

I have a Panel based user control. This is just a simple dashboard with 3 DropDownLists. If I add CompareValidator to my WebForm and assign the ControlToValidate property to the identifier of my custom control, I get the following error:

Control '{0}' referenced by the ControlToValidate property of '{1}' cannot be validated.

I understand why CompareValidator cannot intelligently test anything against Panel . So what do I need to add to my user control so that the validator can validate it?

I tried adding a Text property to my panel, which returns a combination of Text properties from 3 DropDownLists. Not.

I tried to find specific interfaces ( ITextControl ) that implement proven controls ( TextBox ) and add them to my user control. Not.

How can I create my own custom Panel-based control that can be checked with regular .net calibrators? (RequiredFieldValidator, CompareValidator, etc.)

+6
source share
1 answer

If you don't already have one, you need to add the ValidationProperty attribute to your class so that it knows which property to use for validation:

 [ValidationProperty("Text")] [ToolboxData("<{0}:YourCustomControl runat=server></{0}:YourCustomControl>")] public class YourCustomControl : WebControl ... 
+5
source

Source: https://habr.com/ru/post/915309/


All Articles