I am trying to add a css form code . My website uses a master page . I am getting the error The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).
my code snipet
string CssClass = string.Format("{0}/{1}?$BUILD$", BaseImageUrl, CssFileName);
HtmlLink css = new HtmlLink();
css.Href = CssClass;
css.Attributes["rel"] = "stylesheet";
css.Attributes["type"] = "text/css";
Header.Controls.Add(css);
Any suggestions?
You can’t modify the
Controlscollection of the head tag, as the code in the header contains code blocks. So, you have two options:Remove the code blocks from the header and put the data in the header from code behind.
Put a container inside the head tag (for example a
PlaceHolder) and add the link to theControlscollection of the container.