Thursday, November 15, 2007

Editing Meta Tags From Code Behind

Dynamically change the content of meta tags from the code behind. This allows you to feed the meta tags with content from a database or other dynamic content.

In your aspx source code do:

<meta id="metaDescription" name="description" content="" runat="server" />

In your aspx code behind do:

metaDescription.Content = "Description goes here"

The key is the runat="server" and the unique id within the meta tag. This allows you to "see" it in your code behind and manipulate it before sending it to the browser.

No comments: