Solved

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

Posted on 2010-08-19
5
432 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

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 …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

740 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