Trek Innovations

Thoughts For You

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

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

Error Page

Error Page

 

Basically this error occurs when a code block is placed in the MasterPage like this

<%@  Master Language=”C#” AutoEventWireup=”True” Inherits=”TrainingWeb” CodeBehind=”TrainingWeb.master.cs” %>

<%@ Register Src=”UserControls/TopMenu.ascx” TagName=”TopMenu” TagPrefix=”uc1″ %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head id=”Head1″ runat=”server”>

    <meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />

    <title></title>

    <link href=”styles.css” rel=”stylesheet” type=”text/css” />

 

    <script language=”JavaScript” src=’<%= ResolveClientUrl(“~/mm_menu.js”)%>‘></script>

 

</head>

 

<body>

    <form id=”form1″ runat=”server”>  

    <asp:ContentPlaceHolder ID=”ContentPlaceHolder1″ runat=”server”>   

 

    </asp:ContentPlaceHolder>

  

    </form>

</body>

</html>

 

As you can see from the above code with the highlited colour if you mention the code block like this you can get the above error.

 

SOLUTION:

 

In order to avoid this error just  copy the codeblock from the head tag to the content place holder in the master page like this

 

<%@  Master Language=”C#” AutoEventWireup=”True” Inherits=”TrainingWeb” CodeBehind=”TrainingWeb.master.cs” %>

<%@ Register Src=”UserControls/TopMenu.ascx” TagName=”TopMenu” TagPrefix=”uc1″ %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

 

<head id=”Head1″ runat=”server”>

    <meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />

    <title></title>

    <link href=”styles.css” rel=”stylesheet” type=”text/css” />

 

</head>

 

<body>

    <form id=”form1″ runat=”server”>

  

    <asp:ContentPlaceHolder ID=”ContentPlaceHolder1″ runat=”server”>

       

 

    <script language=”JavaScript” src=’<%= ResolveClientUrl(“~/mm_menu.js”)%>‘></script>

 

    </asp:ContentPlaceHolder>

  

    </form>

</body>

</html>

 

This solves the problem.

Share This Post No comments

No comments yet. Be the first.

Leave a reply