Friday, September 29, 2006

Create Dynamic headers in ASP.NET 2.0

Kids-n-Fun is a dynamic site. All content is stored in a database. I have some code (VB.Net) to create the content tags in the header dynamically.

If you using a Masterpage use this in the load event:
Dim myPage as new Page
Dim myHTMLHead as new HtmlHead
Dim myHTMLMeta as new HTMLMeta

myPage = thisPage
myHTMLHead =CType(myPage.Master.FindControl("MasterHeader"), HtmlHead)
myHTMLMeta.Name = "description"
myHTMLMeta.Content = "your description"
myHTMLHead.Controls.Add(myHTMLMeta)

myHTMLMeta.Name = "keywords"
myHTMLMeta.Content = "your keywords"
myHTMLHead.Controls.Add(myHTMLMeta)

If you don't use master pages (you should!) use this code instead:

myHTMLHead=CType(myPage.Header, HtmlHead)

The rest of the code is the same.

No comments: