Master page title disappearing

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?
 
K

Karl Seguin [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top