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

Posted on 2008-01-25
Medium Priority
Last Modified: 2013-11-26
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

Question by:paolotrav
  • 3
  • 2

Expert Comment

ID: 20762941
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" />


Author Comment

ID: 20763058
Thanks for the response.

Well according to asp.net you can implement the extender with or without the . I have tried what you suggested but i am still getting the same runtime error.

Expert Comment

ID: 20763074
Is your MyCalendar css class setup?

Accepted Solution

quanmac earned 1000 total points
ID: 20763136
Please check: http://forums.asp.net/p/1172295/2108775.aspx#2108775

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

Author Closing Comment

ID: 31425154
Thank you - that's exactly what it was.  I wrapped the following code:

<script type="text/javascript" src="<%=ResolveClientUrl"~/JavaScripts/JSFunctions_UI.js") %>

...in the MasterPage with

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question