Getting error about Controlls collection cannot be modified when using AJAXToolKit’s calender extender

asp.netwebforms

I am trying to add the CalenderExternder feature from the AJAXTool kit. When I add the control to my page, build, and debug I get the following error:

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) +9600379
AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(Control control) +702
AjaxControlToolkit.ExtenderControlBase.OnLoad(EventArgs e) +62
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Here is my entire code for the page, it works fine as long as I dont have the tag in my code. i ahve the tool kit registered in my web.config file and the masterpage is useing the ToolkitScriptManager

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/AdminLayout.Master" AutoEventWireup="true" CodeBehind="ManageReleaseInfo.aspx.cs" Inherits="FFInfo.Staff.Sections.ManageReleaseInfo" %>
<asp:Content ID="phContent" ContentPlaceHolderID="phContent" runat="server">
<h2 class="text-center">
    <asp:Literal ID="lblTitle" runat="server" />
</h2>

<asp:Label ID="lblResults" CssClass="text-error" runat="server" />

<asp:ValidationSummary ID="vsErrorSummary" CssClass="text-error" DisplayMode="BulletList" HeaderText="The following errors have been found:" runat="server" />

<p>
    What section is this for?
    <asp:DropDownList ID="ddlSectionList" AppendDataBoundItems="true" runat="server">
        <asp:ListItem Value="-1" Text="Select Section Title" />
    </asp:DropDownList>

    <br />Release Title:
    <asp:TextBox ID="tbReleaseTitle" Columns="50" runat="server" />
    <asp:RequiredFieldValidator ID="ReleaseTitleRequired" ControlToValidate="tbReleaseTitle" Display="Dynamic" CssClass="text-error" Text="*" ErrorMessage="Please there the release title." runat="server" />

    <br />Platform:
    <asp:DropDownList ID="ddlPlatform" AppendDataBoundItems="true" runat="server">
        <asp:ListItem Value="-1" Text="Select Platform" />
    </asp:DropDownList>

    <br />Publisher:
    <asp:DropDownList ID="ddlPublisher" AppendDataBoundItems="true" runat="server">
        <asp:ListItem Value="-1" Text="Select Publisher" />
    </asp:DropDownList>

    <br />Release Location:
    <asp:DropDownList ID="ddlLocation" AppendDataBoundItems="true" runat="server">
        <asp:ListItem Value="-1" Text="Select Locaiton" />
    </asp:DropDownList>

    <br />Estimated Release Date:
    <asp:DropDownList ID="ddlReleaseDate" AppendDataBoundItems="true" runat="server">
        <asp:ListItem Value="-1" Text="Select Estimated Date" />
    </asp:DropDownList>

    <br />Exact Release Date:
    <asp:TextBox ID="tbReleaseDate" AutoCompleteType="Disabled" runat="server" />
    <asp:CalendarExtender ID="ceReleaseDate" TargetControlID="tbReleaseDate" runat="server" />
    <asp:RegularExpressionValidator ID="ReleaseDateCheck" ControlToValidate="tbReleaseDate" ValidationExpression="^([0-9]{1,2})[./-]+([0-9]{1,2})[./-]+([0-9]{2}|[0-9]{4})$" Display="None" ErrorMessage="Please enter a valid date in MM/DD/YYYY format please." runat="server" />
</p>
</asp:Content>

Best Solution

After going to get some dinner and coming back I started googleing this again and found a very realvent post at http://forums.asp.net/t/1172295.aspx/1

In testing I have bundled sytles on my master page that are causing the problem. I simply had to wrape the style.render tag, in my tag, with a PlaceHolder tag. Once that was done everything is working great.

Related Question