Setting Page title doesn't work

Can Poyrazoğlu picture Can Poyrazoğlu · Aug 23, 2011 · Viewed 16k times · Source

I've got a strange problem that setting the Title property of my ASP.NET page does not have any effect, in code level. It doesn't throw an exception either. My class is a derived class of Page class but I am not overriding anything about title.

In the code I have this line:

Title = "About";

While debugging, I'm at that line, I put my cursor over Title as regular, and it displays "" an empty string, which is expected, I step down that line, expecting (obviously) Title to have the value "About" but when I hover, I still get an empty string. Property setting doesn't work. And yes, it is empty in output page too. Well, am I missing something there?

Answer

Matthieu Charbonnier picture Matthieu Charbonnier · Nov 25, 2013

If you want to set the Title from C# code, make sure you don't set a title in the aspx page. (even a blank title will override the Title from the C# code)

This following code will override the Title set in C# code by an empty string:

<%@ Page Language="C#" Title="" ... %>

You have to remove the Title property to be able to set it in C# code:

<%@ Page Language="C#" ... %>