Tuesday, September 18, 2012

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

I've encountered this error a few times with my own custom controls and with the AjaxToolkit when I was upgrading a legacy project with a UI refresh.

In both cases, I had added a .js reference in my <head> tag that resolved using <%= Page.ResolveUrl("my.js") %>.  Apparently .Net doesn't like that when it tries to add a another header dynamically from a control (i.e. registering a new WebResource .css file).


    <head id="headMain" runat="server">
        <link rel="stylesheet" type="text/css" href="~/Content/bootstrap.min.css" />
        <link rel="stylesheet" type="text/css" href="~/Content/bootstrap-responsive.min.css" />
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=Edge" >
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script type="text/javascript" src="<%= Page.ResolveClientUrl("~/Scripts/jquery-1.8.1.min.js") %>"> </script>
        <script type="text/javascript" src="<%= Page.ResolveClientUrl("~/Scripts/bootstrap.min.js") %>"> </script>

Fix the problem by changing it to:

    <head id="headMain" runat="server">
        <link rel="stylesheet" type="text/css" href="~/Content/bootstrap.min.css" />
        <link rel="stylesheet" type="text/css" href="~/Content/bootstrap-responsive.min.css" />
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=Edge" >
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script type="text/javascript" src="<%= Page.ResolveClientUrl("~/Scripts/jquery-1.8.1.min.js"%>"> </script>
        <script type="text/javascript" src="<%= Page.ResolveClientUrl("~/Scripts/bootstrap.min.js"%>"> </script>



Blog and blog would be of advantage, Thank you for providing information about the update. I understand the concept of Trackback. If you have made your blog can be super site., If there could be a great success in Moraere comments and trackbacks or it get, in order to load a lot of people.

National Family Solutions