Error Message, "The Controls collection cannot be modified because the control contains code blocks"
- by Gogster
I'm receiving this error on a page that previously worked fine, in fact the only change I've made to the page recently was to add another asp:TextBox and asp:RequiredFieldValidator control.
The page already had numerous ASP.NET controls on it, so I cannot see why these extra controls would make a difference, anyway I shall post the code below and hopefully you can see what the error is:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MeetingGenerator.ascx.cs"
Inherits="usercontrols_MeetingGenerator" %>
<%@ Register TagPrefix="cc1" Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" %>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div style="width:498px;height:425px;background-color:#033b2a;text-align:center;padding-top:20px;">
<asp:Label ID="lblDone" CssClass="done" runat="server"></asp:Label>
<asp:Panel id="pnlAddReport" runat="server">
<div>
<img src="../images/banners/add-meeting.png" alt="Add Report" />
</div>
<p>
<asp:ValidationSummary ID="ValidationSummary" CssClass="validationsummary" runat="server" />
<asp:TextBox ID="txtTitle" BorderStyle="None" CssClass="watermark"
Width="250px" Height="22px" runat="server"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" TargetControlID="txtTitle" WatermarkCssClass="watermark"
WatermarkText=" Meeting title" runat="server"></cc1:TextBoxWatermarkExtender>
<asp:RequiredFieldValidator ID="rfvTitle" ControlToValidate="txtTitle" Text=""
ErrorMessage="Please enter the title" Display="None"
InitialValue="" runat="server"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="rfvTitle1" ControlToValidate="txtTitle" Text=""
ErrorMessage="Please enter the title" Display="None"
InitialValue=" Meeting title" runat="server"></asp:RequiredFieldValidator>
</p>
<p>
<asp:TextBox ID="txtDate" BorderStyle="None" CssClass="watermark"
Width="250px" Height="22px" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="ceDate" TargetControlID="txtDate" Format="dd/MM/yyyy" runat="server">
</cc1:CalendarExtender>
<cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender2" TargetControlID="txtDate" WatermarkCssClass="watermark"
WatermarkText=" Meeting Date" runat="server"></cc1:TextBoxWatermarkExtender>
<asp:RequiredFieldValidator ID="rfvDate" ControlToValidate="txtDate" Text=""
ErrorMessage="Please select the meeting date" Display="None"
InitialValue="" runat="server"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="rfvDate1" ControlToValidate="txtDate" Text=""
ErrorMessage="Please select the meeting date" Display="None"
InitialValue=" Meeting Date" runat="server"></asp:RequiredFieldValidator>
</p>
<p>
<asp:TextBox ID="txtMeetingTime" BorderStyle="None" Width="250px" Height="22px" MaxLength="5"
runat="server"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="tweMeetingTime" TargetControlID="txtMeetingTime" WatermarkCssClass="watermark"
WatermarkText=" Time (HH:MM)" runat="server"></cc1:TextBoxWatermarkExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtMeetingTime" Text=""
ErrorMessage="Please enter the meeting time" Display="None"
InitialValue="" runat="server"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" ControlToValidate="txtMeetingTime" Text=""
ErrorMessage="Please enter the meeting time" Display="None"
InitialValue=" Time (HH:MM)" runat="server"></asp:RequiredFieldValidator>
</p>
<p>
<asp:TextBox ID="txtLocation" BorderStyle="None" CssClass="watermark"
Width="250px" Height="22px" runat="server"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender3" TargetControlID="txtLocation" WatermarkCssClass="watermark"
WatermarkText=" Location" runat="server"></cc1:TextBoxWatermarkExtender>
<asp:RequiredFieldValidator ID="rfvLocation" ControlToValidate="txtLocation" Text=""
ErrorMessage="Please enter the location" Display="None"
InitialValue="" runat="server"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="rfvLocation1" ControlToValidate="txtLocation" Text=""
ErrorMessage="Please enter the location" Display="None"
InitialValue=" Location" runat="server"></asp:RequiredFieldValidator>
</p>
<p>
<asp:ImageButton ID="btnAddMeeting" ImageUrl="/images/buttons/addmeeting-btn.gif" runat="server" OnClick="btnAddMeeting_Click" />
</p>
<p>
</p>
</asp:Panel>
</div>
<%@ Master Language="C#" MasterPageFile="/masterpages/Master.master" AutoEventWireup="true" %>
<asp:content ContentPlaceHolderId="additionalhead" runat="server">
</asp:content>
<asp:content ContentPlaceHolderId="additionalbody" runat="server">
<umbraco:Macro Alias="AddMeeting" runat="server"></umbraco:Macro>
</asp:content>
<asp:content ContentPlaceHolderId="bodyContent" runat="server">
</asp:content>
<%@ Master Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title><umbraco:Item field="title" runat="server"></umbraco:Item></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="/js/jQueryString-2.0.2-Min.js"></script>
<link rel="stylesheet" type="text/css" href="/css/Styles.css" />
<link rel="stylesheet" type="text/css" href="/css/Layout.css" />
<link rel="stylesheet" type="text/css" href="/css/Forms.css" />
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$('#uploadAgenda').hide();
$('#uploadMinutes').hide();
$('#<%=txtSearchEAA.ClientID%>').val('Search EAA');
var st = $.getQueryString({ ID:"search" });
if (st != '') {
$('#<%=txtSearchEAA.ClientID%>').val(st);
};
$('#<%=txtSearchEAA.ClientID%>').click(function() {
$('#<%=txtSearchEAA.ClientID%>').val('');
});
});
</script>
<script type="text/C#" runat="server">
protected void btnSearch_Click(object sender, EventArgs e)
{
Response.Redirect("/members/search-results?search=" + txtSearchEAA.Text);
}
</script>
<asp:ContentPlaceHolder id="additionalhead" runat="server"></asp:ContentPlaceHolder>
<umbraco:Item field="AdditionalHead" runat="server"></umbraco:Item>
</head>
<body style="background-color:#e5e5e5;">
<script runat="server">
protected void btnLogout_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect("/login");
}
</script>
<form id="form1" runat="server">
<asp:ContentPlaceHolder id="additionalbody" runat="server"></asp:ContentPlaceHolder>
<div class="wrapper">
<div class="content">
<div class="banner">
<div class="bannerSearchSpacer">
<a href="/home"><h1><span>EAA</span></h1></a>
</div>
<div class="aboutEAA">
</div>
<div class="bannerSearchAligns">
<div class="searchbox">
<asp:TextBox ID="txtSearchEAA" CssClass="watermark"
Width="155px" runat="server"></asp:TextBox>
</div>
<div class="searchButton">
<asp:ImageButton ID="imbSearch" ImageUrl="/images/buttons/go.gif" OnClick="btnSearch_Click" runat="server" />
</div>
<div style="clear:both;"></div>
</div>
<div class="loginBox">
<dl>
<dt>Hello</dt>
<dd><umbraco:Macro Alias="MemberName" runat="server"></umbraco:Macro></dd>
<dt>Arena</dt>
<dd><umbraco:Macro Alias="MemberArena" runat="server"></umbraco:Macro></dd>
</dl>
<div><asp:ImageButton ID="btnLogout" ImageUrl="/images/buttons/logout.gif" runat="server" OnClick="btnLogout_Click" /></div>
</div>
<div style="clear:both;"></div>
</div>
<div id="contentarea">
<div class="menuLeft">
<div class="menuPlaceholder">
<umbraco:Macro Alias="DynamicMenu" runat="server"></umbraco:Macro>
</div>
</div>
<div class="mainBody">
<asp:ContentPlaceHolder id="bodyContent" runat="server"></asp:ContentPlaceHolder>
</div>
<div style="clear:both;"></div>
</div>
</div>
</div>
</form>
<umbraco:Macro Alias="MemberAnalytics" runat="server"></umbraco:Macro>
</body>
</html>