Last event in page that can still affect a page's viewstate

白昼怎懂夜的黑 提交于 2019-12-01 11:39:03

In the ASP.net page lifecycle the order goes (this is the short version):

Preinit -> Init -> Load Viewstate -> Page Load -> Events -> PreRender -> Save Viewstate -> Render -> Unload

Places where changes to viewstate are persisted in Bold. As a result the last chance you have to modify viewstate and have it persisted is PreRender (technically you could handle SaveViewState and that would be your last chance to modify viewstate and have it saved).

MSDN: http://msdn.microsoft.com/en-us/library/ms178472.aspx#additional_page_life_cycle_considerations

Handling SaveViewState:

public partial class MyPage: System.Web.UI.Page
{
    protected override object SaveViewState()
    {
        // manipulate viewstate objects here -- Last Chance
        return base.SaveViewState();
    }

    protected void Page_Load(object sender, EventArgs e)
    {

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