locked
add meta tag to header dynamically RRS feed

  • Question

  • User-1106823036 posted

    I wan to add a meta tag to the head dynamically

    this is my code

    Dim fbTitle As New HtmlMeta
    
            fbTitle.Attributes.Add("property", "og:title")
            fbTitle.Content = "test"
            Page.Header.Controls.Add(fbTitle)

    it throws this error

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

    what is wrong.

    Thank you in advance for help

    Tuesday, January 19, 2016 8:57 AM

Answers

  • User-1106823036 posted

    I found the solution

     Dim headTag As New HtmlHead()
            Dim metaTag As New HtmlMeta()
            metaTag.Attributes.Add("property", "og:title")
            metaTag.Content = "test"
    
            headTag.Controls.Add(metaTag)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 19, 2016 9:07 AM

All replies

  • User-1106823036 posted

    I found the solution

     Dim headTag As New HtmlHead()
            Dim metaTag As New HtmlMeta()
            metaTag.Attributes.Add("property", "og:title")
            metaTag.Content = "test"
    
            headTag.Controls.Add(metaTag)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 19, 2016 9:07 AM
  • User753101303 posted

    Hi,

    This message is telling you it can't be done if your ASPX markup already uses a <% %> block for this header control. Is this the case?

    Edit: use "view source" but here you create a new header control and add the meta to it but the header control for now is not part of the page. So the code doesn't show any error but more likely doesn't do what you want.

    Tuesday, January 19, 2016 9:08 AM