My ASP.NET 1.1. app dynamically loads a user control into a PlaceHolder
control that exists in an aspx page. The user control is loaded during the
Page_Load event of the aspx. The PlaceHolder's EnableViewState property
value is "true".
In the user control's Page_Load event procedure I want to read/write to the
ViewState.
Writing to the ViewState, like this, seems to be no problem:
this.ViewState["MyKey"] = someValue;
But attempting to read the value back from the ViewState causes an exception
to be thrown: "Object reference not set to an instance of an object"
someValue = this.ViewState["MyKey"].ToString();
I threw this.TrackViewState(); in the user control's Page_Load event
procedure to see if that was required, but apparently no dice.
What must I do to be able to use ViewState of the user control? Note that I
don't really care if I'm using the ViewState of the user control or of the
page that hosts the user control (I just don't want to store the value in
the Session).
Thanks!