Solved

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

Posted on 2010-08-19
5
438 Views
Last Modified: 2013-11-08
Hi, I am trying to dymanically create the metatags for the title, description and keywords. This is being done in the vb script in a page that has its own master page. I have looked at other similar issues and it seams to imply that this error is because there is some java script in the header section and this should be moved to the page load section, which I cannot see how to do.
My master page header looks like this:

<head id="Head1" runat="server">
        <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
       <script type="text/javascript">
        function RefreshPage() {
            var pgeId = '<%= Page.ClientID %>';
            _dopastBack(pageId, 'Myargs');
        }
        function showall() {
            var sPath = window.location.pathname;
            var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
            window.location.href = sPage;
        }
</script>

I then have a child page:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>

and in the onpage load in the VB script for the page have:
Dim HeadTitle As New HtmlMeta
        HeadTitle.Name = "Title"
        HeadTitle.Content = "This page is about - " + myTable(0)("Description")
        Header.Controls.Add(HeadTitle)

But I get the error message:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
on the line:
Header.Controls.Add(HeadTitle)
any suggestions to work arround this ?
0
Comment
Question by:Simon Cripps
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:puru1981
ID: 33473178
are you using scriptmanager then try the below

Replace all your <%=  %> tags with <%#  %>

0
 
LVL 9

Accepted Solution

by:
puru1981 earned 500 total points
ID: 33473207
0
 

Author Comment

by:Simon Cripps
ID: 33473273
As far as I know I'm not using script manager and I also can't see any place where I'm using <%=  %>.
Are these implied when you use content placeholders?
So I can't find which bits to fix from your suggested solution. Appologies for my ignorance
0
 
LVL 9

Expert Comment

by:puru1981
ID: 33473738
yes,

have you visited the link above.

it should solve your problem

this occurs mostly when something is not within form tag. which is in your case you are trying to write something in header.

here you can see that the function you are writing is in head which is outside the form tag.

It would be better if you can write the title, metatags and descriptions in codebehind.
MasterPage master= (MasterPage)this.Master;

            master.Keywords = "keywords";
            master.Description = "Description";
            this.Title = "title";

Open in new window

0
 

Author Closing Comment

by:Simon Cripps
ID: 33483663
Many thanks have applied what the article was implying and the issue is now resolved.
Cheers
0

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question