Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2010-08-19
5
Medium Priority
?
454 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month21 days, 2 hours left to enroll

810 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