CalendarExtender - Exception is generated when using this control...

We are using Visual Studio Professional 2005, and the Ajax Control Toolkit version 1.0.10618.0

When running the attached code snippet in an aspx page I get the following stack trace:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:

[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
   System.Web.UI.ControlCollection.Add(Control child) +2108047
   AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(Control control) +757
   AjaxControlToolkit.ExtenderControlBase.OnPreRender(EventArgs e) +115
   System.Web.UI.Control.PreRenderRecursiveInternal() +86
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041

Thank you in advance for any suggestions.

<asp:TextBox ID="txtTest" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtTest" Format="MM/dd/yyyy" CssClass="MyCalendar">

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I believe you need to have a button to trigger the calendar extender:

<asp:TextBox ID="txtStart" CssClass="TextBox" runat="server" Width="155px" />&nbsp;
<asp:ImageButton runat="Server" ID="btnCalS" ImageUrl="graphics/Icons/Calendar3.png" AlternateText="Click to show start date calendar" />&nbsp;                          <cc1:CalendarExtender ID="cldStart" TargetControlID="txtStart" PopupButtonID="btnCalS" Format="MM/dd/yyyy" runat="server" />

paolotravAuthor Commented:
Thanks for the response.

Well according to you can implement the extender with or without the . I have tried what you suggested but i am still getting the same runtime error.
Is your MyCalendar css class setup?
Please check:

I beleive there is a solution there, it might be something to do with your Page Directive at the top of your page.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paolotravAuthor Commented:
Thank you - that's exactly what it was.  I wrapped the following code:

<script type="text/javascript" src="<%=ResolveClientUrl"~/JavaScripts/JSFunctions_UI.js") %> the MasterPage with
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.