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

后端 未结 7 1844
别那么骄傲
别那么骄傲 2020-11-30 02:35

I am trying to create dynamic meta tags in C# but it gives the following error:

The Controls collection cannot be modified because the control conta

相关标签:
7条回答
  • 2020-11-30 03:42

    I have had the same issue that I solved this way:

    Instead of adding the meta to the current page header that caused the same error as you had:

    Page.Header.Controls.Add(meta);
    

    I used this instead:

     Master.FindControl("YourHeadContentPlaceHolder").Controls.Add(meta);
    

    and it works like a charm.

    0 讨论(0)
提交回复
热议问题