The Controls collection cannot be modified because the control contains code blocks
I’m pretty much sure many of you have encountered this error if you have been using Code blocks inside your ASP.NET master pages for example,
1: <img src='<%= Page.ResolveUrl("~/image/top-mnu-agents.jpg") %>' alt="Agents" name="agents"
2: width="109" height="42" border="0" id="agents" /></a>
Let’s say you want to use code blocks inside your JavaScript code, for example
1: function PreloadImages()
2: {
3: /*MM_preloadImages('<%= Page.ResolveUrl("~/image/top-mnu-property.jpg") %>',
4: '<%= Page.ResolveUrl("~/image/top-mnu-agents.jpg") %>',
5: '<%= Page.ResolveUrl("~/image/top-mnu-company.jpg") %>',
6: '<%= Page.ResolveUrl("~/image/top-mnu-contact.jpg") %>');*/
7: }
Is this going to work? Make a guess! No, its not! Bump! Even though the code block is inside a comment block! How’s that! If you are curious why, ask the guys at Microsoft
The workaround to this problem is Data Biding Expressions. Milan Negovan has discussed this in greater detail in this article.
Happy Programming!