11 November 2010

How to use ASP.Net validators with a User Control?

ASP.Net validators and user controls (ascx) are great. They save us a lot of time.
But when we mix a User Control and a ASP.Net validator the following error occurs:

Control 'UserSelector' referenced by the ControlToValidate property of 'rvUserSelector' cannot be validated.

The solution to this problem is to use the attribute ValidationProperty on the User Control:

public partial class UserSelector : UserControl

In this example the UserID property of the User Control is used by the validators to perform the validation.

To end, I would like to thank you Alexandre Simões for his help in solving this issue.

No comments: