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
Check out the solutions at "The Controls collection cannot be modified because the control contains code blocks"
The accepted solution on the other question worked for me -- change instances of <%=
to <%#
, which converts the code block from Response.Write
to an evaluation block, which isn't restricted by the same limitations.
In this case though, like the accepted solution here suggests, you should add the controls to something other than a masterpage ContentPlaceHolder element, namely the asp:Placeholder
control suggested.