0

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.

2
  • 1
    Can you add a code snippet where the required span tag is created? Commented Nov 12, 2009 at 15:05
  • That's what I'm saying. BaseValidator handles the render of the SPAN tag. I do not need to override RenderChildControls like normal when creating composite controls. The SPAN tag is rendered by the default and I do not need to modify the output HTML. Commented Nov 12, 2009 at 17:08

2 Answers 2

1

Maybe you should consider using Excentrics World's free calendar popup. I think it has all the functionality you described and it has already been built.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm building a complete set of controls for my company. This is only one of about 50 others. I'm building them to save money for the company, and to ensure they're open source, fully documented, and relatively easy to modify.
0

If you're using a template, call the InstantiateIn() method....

1 Comment

The ASCX control is being used as a template that can be re-used over and over. It does not implement ITemplate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.