I have two dynamic controls that are generated depending on a radio button list selection, which keep their values on postback, however, when I change to another control type I get an error on the viewstate tree because it is expecting anther object type. Is there a way I can delete the previous object from the viewstate when I change the type?
This is a simplified code example to make it easier to examine
if (rblFilter.SelectedValue == "1")
{
var object1 = new object();
holder.Controls.Add(object1);
}
else
{
var object2 = new object();
holder.Controls.Add(object2);
}
The error I get is the following
"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."