Wednesday, February 1, 2012

The Controls collection cannot be modified because the control contains code blocks

Today once I reached office I was with this type of error, after some time of debugging I moved my script code from <head> section to <body> section, and the error got disappered :)

i.e.
    <head runat="server">
        <title></title>
        </head>
    <body>
        <form id="frmTest" runat="server">
           --------------Your code goes here-------------
        </form>   
        <script language="javascript" type="text/javascript">
         function validate() {
                if (document.getElementById("<%=txtName.ClientID %>").value == "") {
                    alert("Name is missing.");
                    document.getElementById("<%=txtName.ClientID %>").focus();
                    return;
                }
         }
        </script>
     </body>
    </html>

No comments:

Post a Comment