can someone confirm my understanding about asp.net live cycle?

隐身守侯 提交于 2019-12-06 10:18:55

问题


my goal is to find a way to update the title of the page at the very last moment before it get created

I have a master page and a content place holder that always contain a page with a specific property.

that property can be updated anywhere in the code but I want the final value of that tag to be the html title

is the prerender event of that page the best place to set the title?


回答1:


PreRender is one place where you could set the title, another -later- is PreRenderComplete:

protected void Page_Init(object sender, EventArgs e)
{
    this.PreRenderComplete += Page_PreRenderComplete;
    this.SaveStateComplete += Page_SaveStateComplete;
}

Edit: Just noticed that you can even use SaveStateComplete event, that should be latest place where you could change the title:

protected void Page_PreRenderComplete(object sender, EventArgs e)
{
    Page.Title = "late title";
}


protected void Page_SaveStateComplete(object sender, EventArgs e)
{
    Page.Title = "very late title";
}

Some additional informations about page-title in masterpages and Site Map Data:

Dynamically Setting the Page's Title in ASP.NET 2.0



来源:https://stackoverflow.com/questions/10525088/can-someone-confirm-my-understanding-about-asp-net-live-cycle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!