Reputation: 1
I'm trying to programmatically add a <meta>
. It is working fine but problem is that it is not adding the tag just below title tag in header section of the page:
Page.Title = "TestPage";
HtmlMeta redirectMetaTag = new HtmlMeta ();
redirectMetaTag.HttpEquiv = "X-UA-Compatible";
redirectMetaTag.Content = "IE=9";
this.AbcHead.Controls.Add(redirectMetaTag);
In my ASPX page there is JavaScript just below empty title tag in header section, so whenever I am trying to add above code on Page_Load(), the meta tag always comes after JavaScript tag. So can anyone suggest how to add meta tag just below title tag?
Upvotes: 0
Views: 774
Reputation: 1
After digging into this I got the answer:
phMetaTag.Controls.AddAt(1, redirectMetaTag);
This will place my meta tag just after title tag.
Upvotes: 0
Reputation: 48686
If this is ASP.NET WebForms, which looks like it might be, you can add a PlaceHolder control to your form anywhere you please, like this:
<asp:PlaceHolder id="phMetaTag" runat="server" />
Then just do this:
Page.Title = "TestPage";
HtmlMeta redirectMetaTag = new HtmlMeta ();
redirectMetaTag.HttpEquiv = "X-UA-Compatible";
redirectMetaTag.Content = "IE=9";
phMetaTag.Controls.Add(redirectMetaTag);
Upvotes: 2