I am receiving the following error message after an HTTP POST on an ASP.NET form hosted inside a UserControl:
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.
What is important when you are adding controls dynamically is on which event you are adding them.
If you added controls on events that occur after load, they will be part of the viewstate you send to the client.
You will have to add those controls again before
LoadViewState is called.
If you run into cases where the the decision of which controls to add is itself stored in the
ViewState or the value of a control, then remember even before the
ViewState is loaded, this data is available in
Refer the asp.net page life cycle