tags:

views:

23

answers:

2

Im trying to add metatag programatically to my page in asp.net using:

HtmlMeta meta = new HtmlMeta();
meta.Name = "keywords";
meta.Content = "test,test1";
this.Master.Page.Header.Controls.Add(meta);

but the Master.Page.Header is always NULL.

Any ideias?

A: 

Try this:

HtmlHead head = this.Master.Page.Header;
HtmlMeta meta = new HtmlMeta();
meta.Name = "Description";
meta.Content = "Friendly and relevant content";
head.Controls.Add(meta); 
IrishChieftain
Can you highlight how that is really any different?
Michael Haren
I created a Header object...
IrishChieftain
Actually, what Frederic said could be the issue...
IrishChieftain
`this.Master.Page.Header` will still be null, regardless of whether or not you store it in a variable
Josh Stodola
+2  A: 

The <head> element of your master page must have the runat="server" attribute. If it doesn't, Page.Header will always be null.

Frédéric Hamidi