11 April 2012

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

No comments:

Post a Comment