I have a webcontrol which adds a textbox and a requiredFieldValidator inside of its CreateChildControls method.
I always add the validator in the CreateChidControls method to the controlcollection - here's the reason why:
I have an IsRequired property on the webcontrol that sets the child validator enabled or disabled depending on this property of my webcontrol. If I don't always include it (so its rendered), I will get a viewstate mismatch when the control moves from IsRequired to NOT isRequired.
When the IsRequired is set to false, the framework does not include a Page_Validators declaration in the javascript - which is proper.
However it appears, especially when my control is placed inside a Panel control, that the framework sometimes gets confused and tries to validate the page even when the validator's Enabled property is set to False- results in a Page_Validators undefined error.
Anyone have similiar experiences?