Anirudh
Anirudh

Reputation: 591

Adding metatags to Header in ASPX page

    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

Answers (1)

s_hewitt
s_hewitt

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

Related Questions