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

后端 未结 7 1878
别那么骄傲
别那么骄傲 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.

提交回复
热议问题