Reputation: 591
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
Literal lTags = new Literal();
lTags.Text = "<meta name=\"MetaTagsDemo\" content=\"Meta demo tag\" />";
this.Header.Controls.Add(lTags);
}
I have the the above code in my default.aspx.cs. When Default.aspx page is loaded I do see the control getting added within section but on top of the page (very 1st line in the page), the html display is "".
What am I doing wrong here?
I have another page named Browse.aspx where I have the same feature but this page doesn't show the html output.
Upvotes: 0
Views: 460
Reputation: 4302
Your control lTags is a Literal
, but it should be a HtmlMeta
.
If you want to use a Literal
, you need to include the entire meta tag in the Text property -
lTags.Text = "<meta name=\"MetaTagsDemo\" content=\"Meta demo tag\" />".
Otherwise, use HtmlMeta
:
HtmlMeta lTags = new HtmlMeta();
lTags.Name = "MetaTagsDemo";
lTags.Content = "Meta demo tags";
Upvotes: 1