I am writing a DateValidator control to function as a validator of all type for dates.
It will function as an Required validator, a Min/Max validator, and a Range Validator for date comparisons on the client side.
All in all, I have it written and it functions: In an ASPX page.
For some reason, when adding it into an ASCX User Control to be used as a template, it does not render the required <span>
tag and thus generates a JavaScript null reference when checking to make sure the control exists before validation continues.
My class inherits BaseValidator
and thus does not override RenderChildControls
since I don't need to modify the output. To add my custom javascript, I use the OnPreRender
method to RegisterExpandoAttributes
to the control, but this cannot fire in an ASCX since the control (the span tag) is never rendered.
Has anyone encountered this and if so, what did you do to fix it?
EDIT:
Ok, after another 3 hours, I've noticed a very important line missing: When run inside an ASPX page, this appears in the HTML:
<script type="text/javascript">
//<![CDATA[
var Page_ValidationSummaries = new Array(document.getElementById("cal"));
var Page_Validators = new Array(document.getElementById("valTest"));
//]]>
</script>
But when in an ASCX User Control in an ASPX:
<script type="text/javascript">
//<![CDATA[
var Page_ValidationSummaries = new Array(document.getElementById("uc1_cal"));
//]]>
</script>
As you can see, only the Validation Summary is being recognized and not my CustomValidator class inheriting from BaseValidator. If I can iron out why it will solve the problem. Frustrating.