Master page title disappearing

  • Thread starter Thread starter Dunc
  • Start date Start date
D

Dunc

Hi,

I'm using ASP.NET 2.0's master pages feature (very nice), and I'm
setting the page title programatically (Master.Page.Title = "abc";)
based on a database read.

Whenever a button is pushed on the page, the page reloads, the
!Page.IsPostback is [correctly] skipped, but the title on the master
page is reset to the default.

Does anyone know a way to stop this this, or do I have to re-read from
my database every page hit?
 
As you've noticed, the title value isn't automatically kept. How you deal
with that is really up to you. You can reload from the database, you can
store it in viewstate or in the cache.

if (!IsPostBack)
{
Title = "abc";
ViewState.Add("Title", "abc");
}
else
{
Title = (string)ViewState["Title"];
}

Of course, i'd consider storing it in the cache if the titles are global to
each user.

Karl
 
Back
Top