views:

44

answers:

1

I've got a page with a Timer that is being used as a trigger on an UpdatePanel. The page also contains a TabContainer and several TabPanels. Look at this question for more information. Basically, I've got an UpdatePanel as the element in each TabPanel's ContentTemplate, and the UpdatePanel is triggered by the Timer.

My page displays data by reading a database on each tick. I've got the following code running on each Timer.Tick in my codebehind:

protected void timeRefresher_Tick(object sender, EventArgs e)
{
    UpdateLivePageTitle();
}

The UpdateLivePageTitle() function reads the new information from the database and sets Page.Title accordingly. However, this information is of course not sent to the browser because there is no full page postback--only an async postback to the update panels. As a result, my page title is not being updated until the whole page is being posted back, which destroys the purpose of using UpdatePanels in the first place.

I figure there would be a way to do this by using the document.title JS element and call that from within UpdateLivePageTitle(). But as of now, I haven't been able to figure out how to do this. I tried using the following in my UpdateLivePageTitle() function:

string updatePageTitleScript = String.Format("document.title = '{0}'", newPageTitle);
ToolkitScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "UpdatePageTitle", updatePageTitleScript, true);

But the result of this was that my TabContainer stopped rendering. I'm also not sure that would work with the async partial page postbacks, either. Any ideas?

Thanks!

+1  A: 

You forgot the ; from your script.

Oh, and if I remember correctly, the framework should be able to update the title if you just set Page.Title.

Matti Virkkunen
Setting Page.Title doesn't work, which is why I was looking at alternate solutions. The semicolon did the trick. Thank god it was just a silly syntactic problem!
sohum
@sohum: That's odd. I'm sure I saw something page-title related in the library source code. I haven't actually tried it though, so maybe it doesn't work just like that.
Matti Virkkunen