Validating Custom Controls

Published 8.19.2005 by ~mattg

So I was banging my head against the wall today, trying to figure out why I kept getting an error like “Control X referenced by the ControlToValidate property of Y cannot be validated,” where X was a custom web date control and Y was it’s validator.

I searched around and found that the custom web date control needed to have the ValidationPropertyAttribute set above the class so that the validator knew which Property it was to validate. In C#, the declaration would look something like

// C# [ValidationPropertyAttribute("Message")] public class myCustomControl { public string Message { get { return "My Message"}; } /* class implementation goes here */

Obviously this isn’t a full web control, it is simply meant to show you how to set the ValidationPropertyAttribute for your class.

Filed under News

Comments (3)

Comments RSS - Trackback - Write Comment

  1. Barry says:

    So does a validator work with your control now? I had the same problem and I found ValidationPropertyAttribute, so I no longer get the error you describe, but RequiredFieldValidator and CustomValidator just seem to ignore my control. The error message never gets displayed. Still banging my head.

    Posted 9.16.2005 @ 13:09
  2. ~mattg says:

    Well, it seems to work just fine.. At the time I was more interested in getting the error out of there, but that code has gone through our QA testing and seems to have come out without bugs in that particular area. I will definitely go back and investigate that code further to be sure that’s working.

    Posted 9.16.2005 @ 15:15
  3. mht says:

    i have the opposite problem, ive set to return alway true just to test the control but the bound validator always return false; here is the Verified property im using to debug, ive replaced Message with Verified obviously:

    [Browsable(false)]
    public bool Verified {
    get { return true;}
    }

    Posted 12.01.2008 @ 18:14

Write Comment