System.Web​.HttpUnhan​dledExcept​ion: Failed to load viewstate

Event:
Getting error while loading control - the GridView in CreateChildControl that uses ViewState

Error:

System.Web.HttpUnhandledException: 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.

The solution:
Transfer the load of the ViewState to PreRender (from CreateChildControl)

The lesson:
Better understand the life-sycle of loading (seems that no matter the experience, are always making mistakes of a beginner :) ...)

Cheers,
Roi

Comments

Popular posts from this blog

A sharepoint list view of the current month

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters

Export SharePoint 2010 List to Excel with PowerShell