Update PageTitle on Timer.Tick

Posted by sohum on Stack Overflow See other posts from Stack Overflow or by sohum
Published on 2010-06-14T19:02:03Z Indexed on 2010/06/14 19:12 UTC
Read the original article Hit count: 210

Filed under:
|
|
|
|

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!

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET