1

So here is my problem: I have a webpage that is using an asp:TreeView control and a sitemap to draw a menu.

<asp:TreeView ID="CatalogTreeViewControl" runat="server" DataSourceID="dsSiteMap">
</asp:TreeView>
<asp:SiteMapDataSource runat="server" ID="dsSiteMap" ShowStartingNode="False" SiteMapProvider="MyXmlSiteMapProvider"/>

This works like a charm, but I want to use the asp:Menu control instead of the TreeView, så I do this:

<asp:TreeView ID="CatalogTreeViewControl" runat="server" DataSourceID="dsSiteMap" Visible="False">
</asp:TreeView>

<asp:Menu ID="Menu1" runat="server" DataSourceID="dsSiteMap"></asp:Menu>

<asp:SiteMapDataSource runat="server" ID="dsSiteMap" ShowStartingNode="False" SiteMapProvider="MyXmlSiteMapProvider"/>

But this results in the following error:

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

What am I doing wrong here?

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
linnkb
  • 515
  • 3
  • 9
  • 24

1 Answers1

1

I got this problem a long time back. I moved my javascript from the head tag to a form tag and it fixed the problem. These links helped me a lot :

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

http://leedumond.com/blog/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks/

Community
  • 1
  • 1
Srinivas
  • 1,063
  • 7
  • 15
  • 1
    Thanks! Forgot that this control was used in a masterpage and that this masterpage included javascript. – linnkb Jan 31 '13 at 09:54