This post originated from an RSS feed registered with .NET Buzz
by Michael Mello.
Original Post: Dynamically creating the TITLE tag
Feed Title: melloblog
Feed URL: http://www.thauvin.net/errorpage.htm?aspxerrorpath=/Default.aspx
Feed Description: .NET and Everything After.
Every now and then I'll enter some search criteria into Google, and see how some of my pages rank. Lately I've noticed that the searches that return the title links to the feedback of my blogs, don't look so hot.
For example, if you were to type in 'isnumeric in C#' into a Google search, as of this moment, Google will return a link to my post in the second page, which looks like this:
Melloblog - Feedback About Blogs Posted.
Now there is nothing wrong with the way Google is returning the search results, but there is something wrong with my title. It's not very elegant, and could be more descriptive.
Dynamic Title
My answer is to utilize 'runat="server"' within my title tag, to create a dynamic title, based on the blog entry.
<!--Here is the title tag in my html file--> <title id="PageTitle" runat="server"><title>
Now I can programmatically access the title tag in my codebehind.
//declare the title control protected System.Web.UI.HtmlControls.HtmlGenericControl PageTitle;
//make the title of the page, the title of the blog PageTitle.InnerHtml = "Melloblog - " + myBlogs.GetBlogTitle(BlogID);
The 'myBlogs.GetBlogTitle(BlogID)', is simply the method of my class that will return the title of the current blog. If all goes as planned, my search results that point to the feedback pages will return this instead:
Melloblog - IsNumeric in C#
A lot more descriptive, and more likely to be explored by the end user. Stay tuned...