Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Wednesday, September 5, 2012

Adding Page Title, Meta Tags dynamically in ASP.NET

Untitled Document using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = "This is the page title";

// Create two instances of an HtmlMeta control.

HtmlMeta hm1 = new HtmlMeta();

HtmlMeta hm2 = new HtmlMeta();

// Define an HTML <meta> element - description - that is useful for search engines.
hm1.Name = "description";
hm1.Content = "this is the description text of the meta tag";

// Define an HTML <meta> element - keywords - that is useful for search engines.
hm2.Name = "keywords";
hm2.Content = "these are the keywords of the meta tag";

// Get a reference to the page header element.

HtmlHead head = (HtmlHead)Page.Header;

head.Controls.Add(hm1);

head.Controls.Add(hm2);

}
}

No comments:

Post a Comment