Error: The Controls collection cannot be modified because the control contains code blocks (i.e. )

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.

SOLUTION:

Search within the <head> </head> part of your page and look for any content with the following characters “<%” or use ctrl+F to look for them.

Make sure you gather all <% parts and place them in a simple PlaceHolder, no matter if they are placed in style tags, script tags or simple html tags.

Example:

<asp:PlaceHolder runat=”server”>

<script type=”text/javascript” src=”<%# ResolveUrl(“~/scripts/jquery.js”)%>“></script>

<script type=”text/javascript”>

function SearchUser() {

document.getElementById(“<%= txt_search.userID%>“).value = “”;

}

</script>

</asp:PlaceHolder>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s