The Controls collection cannot be modified because the control contains blocks of code (i.e. <% ...%>) ajax toolkit html editor

 <%@ Page Language="C#" MasterPageFile="~/master/111.master" AutoEventWireup="true" CodeFile="Template.aspx.cs" Inherits="_Template" Title="Untitled Page" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor" TagPrefix="cc1" %> <asp:Content ID="Content3" ContentPlaceHolderID="cphhead" Runat="Server"> <script type="text/javascript" src="../css-js/jquery-1.8.3.min.js"></script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="cphcontent" Runat="Server"> <cc1:Editor ID="Editor1" Width="1028px" Height="300px" runat="server" SuppressTabInDesignMode="true" ActiveMode="Design" /> </asp:Content> <asp:Content ID="Content5" ContentPlaceHolderID="cphFooterJS" Runat="Server"> </asp:Content> 

I am trying to add the main ajax editor of an html page with a namespace, but I have this err: System.Web.HttpException: the Controls collection cannot be changed because the control contains blocks of code (i.e. <% ...% >).

How to fix it? thank you for your responses.

+6
source share
6 answers

I encountered this error before. Solution, check your main page if you have javascript with a block <% ...%>, then remove it from the head and add the body to the section.

Hope this helps you.

+29
source

Use it

1 - replace the code block with <% # instead of <% =

After replacing the code block with <% # instead of <% = add the following code to the page load

 protected void Page_Load(object sender, EventArgs e) { Page.Header.DataBind(); } 

After adding the code, run the application, it will work for you.

Happy coding .........

+8
source

Thanks - this is also my problem.

I changed:

  <script src="<%=Page.ResolveClientUrl(String.Format("~/Scripts/jquery-1.7.1{0}.js", IIf(Bshifter4.MvcApplication.UseMinify, ".min", ".chirp")))%>" type="text/javascript"></script> 
+2
source

Remove the javascript block from the header and add it to the body.

0
source

Any data binding expressions in the tag with runat = server throwing this error.

0
source

You must wrap your script tags

-2
source

Source: https://habr.com/ru/post/951201/


All Articles