I am trying to set a value into ViewState but the value isn't saving across postbacks. (I am actually trying to save a seriazable class, but for simplicity I am testing using a simple string value which isn't saving either).
I have tried manually setting the EnabledViewState = true property in the page directive of the master page, and I am also testing to see whether ViewState is enabled at the start of the method, which it is - but still the value is being reset on every postback.
The OnPreRender occurs late enough in the Page Lifecycle so that isn't the issue.
protected override void OnPreRender(EventArgs e)
bool viewState = this.IsViewStateEnabled;
if (ViewState["Test"] == null)
ViewState["Test"] = "This is a test";
string test = (string)ViewState["Test"];