locked
Set meta data dynamically RRS feed

  • Question

  • Hi Guys,

     

    What i am trying is to set page meta data info like Title, meta keyword and meta description from content page but i am not able to do so.

     

    Please help me.

     

    Server Error in '/WEB' Application.

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

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    Source Error:

    Line 935:            tag.Name = "keywords"
    Line 936:            tag.Content = strMetaKeyword
    Line 937:            objPage.Header.Controls.Add(tag)
    Line 938:          End If
    Line 939:

     

    I used below code for setting meta data info

                      'Add title
                        Dim strMetaTitle As String = "strtitle"
                        If Not String.IsNullOrEmpty(strMetaTitle) Then
                            objPage.Title = StripOutAnyExcessiveChar(strMetaTitle)
                        End If

                        'Add Keyword
                        Dim strMetaKeyword As String = "strKeyWords"
                        If Not String.IsNullOrEmpty(strMetaKeyword) Then
                            Dim tag As HtmlMeta = New HtmlMeta()
                            tag.Name = "keywords"
                            tag.Content = strMetaKeyword
                            objPage.Header.Controls.Add(tag)
                        End If

                        'Add Description
                        Dim strMetaDdescription As String = "strDescription"
                        If Not String.IsNullOrEmpty(strMetaDdescription) Then
                            Dim tag As HtmlMeta = New HtmlMeta()
                            tag.Name = "description"
                            tag.Content = strMetaDdescription
                            objPage.Header.Controls.Add(tag)
                        End If

    In master page i have included few css and js links, once i removed those i start working,else not

        <!--main page image slider-->
        <script type="text/javascript" src='<%=ResolveUrl("~/js/jquery.min.js")%>'></script>

        <!--common js file-->
        <script type="text/javascript" src='<%=ResolveUrl("~/js/common.js")%>'></script>

        <!--jquery script for testimonials and news-->
        <script type="text/javascript" src='<%=ResolveUrl("~/js/jcarousellite_1.0.1c4.js")%>'></script>

        <!--for popup-->
        <script type="text/javascript" src='<%=ResolveUrl("~/js/shadowbox.js")%>'></script>

        <!--For Slide show-->
        <script type="text/javascript" src="<%=ResolveUrl("~/js/jquery.slideshow.js")%>"></script>

    For including these js and css i use ResolveURL function

     

    Thanks in advance


     



    Thanks & Regards, BL Karwasara SSE | MCPD-EA 3.0
    Wednesday, July 13, 2011 4:56 PM

Answers

  • Anyways i got solution for this...

     

    its here

     

    http://blkarwasara.blogspot.com/2011/07/controls-collection-cannot-be-modified.html


    Thanks & Regards, BL Karwasara Sr Software Engineer MCPD-EA 3.0
    • Marked as answer by BL Karwasara Wednesday, July 13, 2011 9:12 PM
    Wednesday, July 13, 2011 9:12 PM

All replies

  • to register your script files use the Page.Register***Script***() methods in the Page.Load.
    Wednesday, July 13, 2011 7:50 PM
  • Hey Houwing,

     

    Thanks for your response but could please elaborate this.

     

    Thanks

    BL Karwasara

    Avanade India

    Accenture services pvt ltd


    Thanks & Regards, BL Karwasara SSE | MCPD-EA 3.0
    Wednesday, July 13, 2011 7:54 PM
  • Anyways i got solution for this...

     

    its here

     

    http://blkarwasara.blogspot.com/2011/07/controls-collection-cannot-be-modified.html


    Thanks & Regards, BL Karwasara Sr Software Engineer MCPD-EA 3.0
    • Marked as answer by BL Karwasara Wednesday, July 13, 2011 9:12 PM
    Wednesday, July 13, 2011 9:12 PM