Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>) asp.net

Issue:

 

Server Error in 'ASP.Net' Application.


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.

Resolution:

If script files exist in head section of web form, master page or in content page, remove JavaScript from the header section of page and add it to body of the page and run your application it will work for you.

 

or replace the codeblock with <%# instead of <%=.

 

This way you can resolve the above issue.