Dynamic Title Tags - High-Flying C# Coding Tips


Sponsored Links

73058_New Scooba® 230 Floor Washing Robot + Free Shipping!

 

Dynamic Title Tags

Here we'll look at a way of creating Dynamic Title Tags. (.NET 2.0)

Usually, a HTML page contains a Title tag in the HEAD section. Title tags provide the title which the browser displays at the top of the browser. The value is usually set in the static HTML, fixed in code by the time it is presented to the user.

Here is the Title tag in the HEAD section of this actual page.


<title>High-Flying C# Coding Tips - Dynamic Title Tags</title>

But you may want to be able to decide on the title dynamically, that is use C# to control what goes into the title tag in the HTML which the user will see. You may want to do this when the content of the page changes and the name of the page changes.

In this example, we check for existence of the head section first, it it exists we then set the Header.Title property to the string we want. This would need to be called in the Page_Load event so the title exists before the page is sent to the user.



// Provide a title tag in the header
if (Page.Header != null)
{
    Page.Header.Title = "High-Flying C# Coding Tips - Dynamic Title Tags";
}