Browsing all articles in Web Development

Dynamic change of metatags in MasterPage-inherited .aspx page

Posted Posted by Ahmad Barirani in Web Development     Comments No comments
May
7

To change a page’s metatags in codebehind (dynamically), use of HtmlMeta class from System.Web.UI.HtmlControls namespace will do.

Here’s a snippet to change the page’s keywords metatag for example:

HtmlMeta keywords = new HtmlMeta();
keywords.Name = “keywords”;
keywords.Content = “montreal, cinema, hockey, tourism”;
Page.Header.Controls.Add(keywords);

Only, if we apply this code to change metatags in a page that inherits from a MasterPage which has those metatags, then we will find ourselves in an ambiguous situation of having duplicate metatags (duplicate keywords metatag for example).

To avoid this situation, the MasterPage’s metatag must first be removed from the Page.Header.Controls collection.

blog Categories

About Singular Technologies

Location: Montreal, Canada

Services: Internet strategy and marketing. Data mining. Information retrieval. Web analytics.

Featured Website