Friday, March 26, 2010

Page.Title Strangeness

It’s very late and I’m madly trying to get a release out to the client so that I can go home (and have food as I’ve also not had lunch as well) and came across a rather strange problem in ASP.NET.

When trying to set the title of the page in code using a line very similar to the following:

Page.Title = "My new page";
It was ignoring it completely. Even setting the value in the watch window when debugging wouldn’t change the value of the Title property.

After a fruitless twenty minutes or so I spotted what the problem was. It was set in the mark-up to an empty string:

<%@ Page Language="C#" Title="" %>
And this stopped it being set in the code behind. Rather mental! Especially if you do the following:
<%@ Page Language="C#" Title="My page" %> 
When in this case it’s actually set correctly in the code-behind, overriding what is in the mark-up.

No comments: