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

亡梦爱人 提交于 2019-12-01 08:10:47

问题


I am trying to make a strongly typed viewstate object.

public class MyNewPage : ViewStatePage<MyNewPageViewStateStore>

In the implementation of ViewStatePage, I am instantiating an object Store out of this.ViewState["_PageViewState"]. In the derived page, I'll be using that object and making changes to it.

What's the last event called in an asp.net page that can still affect View State? Is it Unload?


回答1:


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)
    {

    }
}


来源:https://stackoverflow.com/questions/8265831/last-event-in-page-that-can-still-affect-a-pages-viewstate

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