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

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

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

    }
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x