Thursday, 15 February 2007

Validate a user control

I created a decimal only usercontrol (basically a text box with a public text property, a required field validator, a Compare validator, a filtered text box Ajax extender, and obviously a couple of validator callout extender).

I wanted to validate the usercontrol using a compare validator on the main form, but took a little while to figure out how to let the validator select it. The fix is quite simple, just add the attribute

[ValidationProperty("Text")]
Enjoy

Ross

4 comments:

Sam said...

Thanks! You saved my butt with this post!

Anonymous said...

Sweet. That saved my time too.

Anonymous said...

Thanks that's great. Did you get client side validation going? I couldn't get it to work.

Unknown said...

Setting the ControlToValidate property of the validator as follows seems to enable client side validation...

ControlToValidate="myUserControl$TextBox1"