ASP.Net Page titles

So you don’t want to have to type your page title onto each and every page of your website, especially if it changes. I understand and have a fix.

In the ASPX file, in the HTML editor change the <Title></Title>
to <title runat="server" id="pageTitle"></title>

Then in your ASPX.VB file, yes you can do a version of this in your C# code too, put the following declariation in:
Protected WithEvents pageTitle AsSystem.Web.UI.HtmlControls.HtmlGenericControl
This will give you access to the title tag as a generic control. You can then access it by addressing it with pageTitle.InnerHTML = "Something"

My default value is to use the assembly information: Dim version As String Dim Title As String With
System.Reflection.Assembly.GetExecutingAssembly Title = CType(.GetCustomAttributes(GetType(AssemblyTitleAttribute), False)(0), AssemblyTitleAttribute).Title version = .GetName().Version.ToString End With pageTitle.InnerText = Title & " (" & version & ")"

In this manor, everytime I update my assembly file, I update all of my pages.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.