Reputation: 1365
Background: I have a toolset of CompositeControls that I use to build forms. The controls themselves tie in to some jquery validation for basic validation tasks.
Problem: I want to make the validation of these CompositeControls more flexible by allowing developers to use the ASP.NET validators (i.e. RegExValidator, RequiredFieldValidator, CustomValidator, etc) to validate the data in one of my CompositeControls.
Example: I'd like the developers to be able to do something like this:
<asp:ValidationSummary runat=server HeaderText="There were errors on the page:" />
<custom:TextBox id='SomeTextBox' Label='Enter Name Here:' text='' runat='server' />
<asp:RequiredFieldValidator runat=server ControlToValidate=SomeTextBox ErrorMessage="Name is required."> *
</asp:RequiredFieldValidator>
I have added the "ValidationProperty" to the composite textbox, but the RequiredFieldValidator (or any ofthe other validators) don't seem to recognize the textbox or the data coming from it. The textbox (and all other custom CompositeControls I built) inherit CompositeControl, have the attribute "ValidationProperty" set to the public property that exposes the data element of the control, and contain a "string ValidationGroup" property as well.
Question: Does anybody know what else or what specifically a Composite Control requires to play nice with the ASP.NET validators (I'd prefer avoiding including instances of all the validator types in the composite control, unless of course that is necessary)?
Upvotes: 1
Views: 666
Reputation: 13965
I last looked into this in about 2005, but from what I remember, there are two separate issues here:
Setting ValidationProperty
is only going to affect the server-side validation, if I'm not mistaken. If you haven't already, check whether the IsValid
property of the validators is set to false
on the server side after you post back.
This may have changed, but I think it was also true that validation controls could only validate controls that had the same naming container as they did.
On the client side, I'm a little hazier, but I think the situation is still that the validation script will look for an element with the client ID corresponding to the server ID it was told to look for, and look for a value
property on that. If you're not exposing one on the client side, it's not going to be able to find anything to validate.
If you have time, it'll help a lot to step through the validation javascript. That'll teach you a LOT about how client-side validation finds the values that it validates.
Hope this helps.
Upvotes: 2