Solved

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now