Error on grid view paging “Failed to load viewstate.. “

I was getting “Failed to load viewstate ..” error when I was trying to load second page of grid.
I had AllowPaging=”true”, grid page size was set but even then in client’s test environment grid paging was not working at all and throwing the following error:

“Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.”.

Setting EnableViewState=false for that grid fixed this error.

#asp-net, #viewstate

Events sequence in page, master page and user controls

Event sequence became complex when master and content page have user and server controls in them. I just tried to check this sequence and my findings are as below:

Content Page_PreInt
Master Page User Control Page_Init
Master Direct Control init event
Content Direct Control init event
Content Page User Control Direct Control init event
Content Page User Control Page_Init
Master Page_Init
Content Page_Init
Content Page_InitComplete
Content Page_PreLoad
Content Page_Load
Master Page_Load
Master Page User Control Page_Load
Master Direct Control load event
Content Direct Control load event
Content Page User Control Page_Load
Content Page User Control Direct Control load event
Content Page_LoadComplete
Content Page_PreRender
Master Page_PreRender
Master Page User Control Page_PreRender
Master Page Direct Control Pre Render event
Content Page Direct Control Pre Render event
Content Page User Control Page_PreRender
Content Page User Control Page Direct Control Pre Render event
Content Page_SaveState

For more details please check this and this.

#asp-net