Jerald.Net
A little VB.Net, SQL, and whatever else comes to mind...

Dynamic Page Titles for ASP.Net

I was wondering if there was a clean way to programatically control the page title in ASP.Net. This is helpful with search engine optimizing techniques. I found a few examples across the web. I tried out a couple and to me, this solution seemed to be a very efficient way to handle the problem.

In the HTML remove the existing <title></title> tags and replace it with the following:

<asp:PlaceHolder id="titlePlaceHolder" runat="server" />

In the Code Behind add the following code:

PageTitle= new System.Web.UI.HtmlControls.HtmlGenericControl("title");
titlePlaceHolder.Controls.Add(PageTitle);
PageTitle.InnerHtml="Some programatically generated information";

Additionally if you have a large number of dynamic pages, adding the Code Behind to each page would be time consuming. By adding it to a User Control like a site navigation control, you minimize the additions for code.


Posted Apr 29 2005, 12:47 AM by Jerald Carter
Filed under:
© Jerald Carter 1999 - 2008
Powered by Community Server (Non-Commercial Edition), by Telligent Systems