The Controls Collection Cannot Be Modified


The Controls Collection Cannot Be Modified Because The Control Contains Code Blocks, The Controls Collection Cannot Be Modified, The Control Contains Code Blocks, Asp.Net, C#, MVC, Controls Collection, Dynamically Append Controls

This issue happens in the following situation.

When there is having code blocks like <%= ... %> on aspx page and We are trying to append controls dynamically from code behind. For example, on the following figure, there is having code blocks on head section. From code behind, we are appending one link to the header section.

The Controls Collection Cannot Be Modified Because The Control Contains Code Blocks, The Controls Collection Cannot Be Modified, The Control Contains Code Blocks, Asp.Net, C#, MVC, Controls Collection, Dynamically Append Controls

The Controls Collection Cannot Be Modified Because The Control Contains Code Blocks, The Controls Collection Cannot Be Modified, The Control Contains Code Blocks, Asp.Net, C#, MVC, Controls Collection, Dynamically Append Controls





For resolving this issue, we have to modify the code block section as shown in the figure.

The Controls Collection Cannot Be Modified Because The Control Contains Code Blocks, The Controls Collection Cannot Be Modified, The Control Contains Code Blocks, Asp.Net, C#, MVC, Controls Collection, Dynamically Append Controls

Code block should be <%# ... %> instead of <%= ... %>
By this way we can resolve this issue.