I have this code to remove an existing meta tag to which i dont have access because it is in the solution dll it comes with but basically, I want to remove the meta tag content it comes with to our company content. The problem is that it is not finding the meta tag and I think is because of the way I am setting the htmlHead = Page.Header; I think i am missing something there.. but not sure.. This code is in a virtual Page_Load in a Base class.
HtmlHead pHtml = Page.Header;
for (int i = pHtml.Controls.Count - 1; i >= 0; i--)
{
if (pHtml.Controls[i] is HtmlMeta)
{
pMeta thisMetaTag = (HtmlMeta)pHtml.Controls[i];
if (thisMetaTag.Name == mName)
{
pHtml.Controls.RemoveAt(i);
}
}
}
I am not sure if i am giving the correct rederence to the header since this is in a virtual Page_Load in a Base class. Also most of this code was taken from (99%) from here Code for meta tag removal and replacement
Any help would be much appreciated
It could be an issue with the order the events occur. I created a new page in ASP.NET
I then used:
When I view the source, I see that the content of the meta tag was modified. Now, you’re issue could be that at the time of looping, the control doesn’t exist (wasn’t added yet) and you’re adding it, and then the built in code is adding it.
EDIT – Suggesting moving code to PreRender incase controls are added after load but before rendering