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.

Comments

  • Anonymous
    December 12, 2013
    Why?

  • Anonymous
    December 12, 2013
    Mark, Can be more specific?

  • Anonymous
    February 17, 2014
    Thanks a lot :)

  • Anonymous
    February 18, 2014
    thanks but why we have to do like this???

  • Anonymous
    February 23, 2014
    It Works. Thanks :)

  • Anonymous
    March 04, 2014
    Sorry! still not working!

  • Anonymous
    March 19, 2014
    Not Working

  • Anonymous
    March 20, 2014
    Thanks!!!

  • Anonymous
    April 02, 2014
    it works, thanks

  • Anonymous
    April 22, 2014
    its working..Thanks.

  • Anonymous
    May 15, 2014
    super..........pppp good

  • Anonymous
    June 22, 2014
    page.header.databind();

  • Anonymous
    July 24, 2014
    In my Javascript in Markup, a code was commented out which contained the characters <% ... %>...which was creating this error. Completely removed it and the error vanished.

  • Anonymous
    August 04, 2014
    Thanks Pradeep it helps

  • Anonymous
    August 12, 2014
    yeah its working thanks a lot.

  • Anonymous
    August 31, 2014
    thankyou very much

  • Anonymous
    September 01, 2014
    IN MASTER PAGE SCRIPT TAG PASTE BEFORE </BODY> TAG

  • Anonymous
    September 25, 2014
    its not working when we use javascipt file

  • Anonymous
    September 28, 2014
    It worked... Thanks

  • Anonymous
    October 07, 2014
    thanks, it helps me.

  • Anonymous
    November 14, 2014
    thank you very much! It saved my time so much!

  • Anonymous
    April 27, 2015
    Please try changing your.net clr version (if it is 4.0 try changing it to 2.0) and run,it worked for me .

  • Anonymous
    May 26, 2015
    The comment has been removed

  • Anonymous
    May 29, 2015
    Replacing the codeblock with <%# instead of <%= renders nothing

  • Anonymous
    February 10, 2016
    Thanks a lot, you save me a bunch of time from headache.