The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)
Last Day I encountered this problem and spent nearly 2 hours for searching for the root cause. The root for this exception is server code block(<% .. %>) inside the master page. I need to read the value of a variable which runs at server from javascript. By default all my script tags are included in the head section of the master page. So, I have attached another script tag to fetch the required value in the head section, in which the server tags included. When I run my program, I got the exception "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)".
For troubleshooting, I started debugging the application. I observed that everything is working fine, but the master page where I added the script, is repeatedly loading. It went into some kind of infinite loop redirecting to itself. I still dont know the reason for this mis-behavior.
The workaround for this is to replace the script tags with <% %> from head section to body. This will solve the problem and everything works as expected.
For troubleshooting, I started debugging the application. I observed that everything is working fine, but the master page where I added the script, is repeatedly loading. It went into some kind of infinite loop redirecting to itself. I still dont know the reason for this mis-behavior.
The workaround for this is to replace the script tags with <% %> from head section to body. This will solve the problem and everything works as expected.
Comments
Post a Comment