Sunday, June 05, 2005

Validatable Controls and Validators

Everyone knows that MCMS controls can't be validated with normal ASP.NET validators. I always had the feeling that common MCMS placeholder controls were not made for validation by default.

Controls, which are to be validated, are bounded with validator controls using their ControlToValidate property. In a web form, if we have a validatable control and a validator, ControlToValidate property (dropdown) of the validator lists all the controls, which can be validated. But the placeholder controls that I've seen up to now are not showed up in the dropdown of the validators.

Normally validators pick the controls which can be validated by them using an attribute -
ValidationPropertyAttribute - ValidationProperty. But normally the placeholder control doesn't have this attribute defined with them - they are not listed in the dropdown of validators - ControlToValidate property.

So if we are designing a custom placeholder control and if we like it to be a validatable control (I always like) then we must have ValidationProperty attribute defined with the class definition.

e.g. If we are creating a placeholder control from BasePlaceholder control, and the property of the control which we want to validate is Html then the class declaration must be

[ValidationProperty("Html")]
public class HtmlValidattableControl : BasePlaceholderControl

2 Comments:

Anonymous Stefan Goßner [MSFT] said...

Hi Chester,

look forward to the MCMS book Mei Ying, Angus, Andrew and myself are currently writing.

We will show there how to use validator controls with normal MCMS placeholder controls.

Cheers,
Stefan

7:45 PM  
Blogger Chester said...

Hi Stefan,

After a while... Good to see you back! I went through the chapter - Validating Placeholder Controls. It had some great controls. But, this post mostly related with ValidationProperty than validators :).

Cheers,
Chester.

8:06 PM  

Post a Comment

<< Home