Hi!
I've got a custom web user control that consists of a panel and 12 imageMaps on it. Now I've added a member variable like this:
ImageMap[] ProfileImages = null;
And in the OnInit method, i do this:
ProfileImages = new ImageMap[12];
ProfileImages[0] = ImageMap1;
ProfileImages[1] = ImageMap2;
ProfileImages[2] = ImageMap3;
...
What I want to do now is to be able to access the image maps using the array in a method like this:
public void DoSomething()
{
for (int i = 0; i < 12; i++)
{
ProfileImages[i].ImageUrl = "someUrl";
ProfileImages[i].DescriptionUrl = "anotherUrl";
}
}
The problem now is that the array is null because of the page-lifecycle. So I tried to add the variable to the ViewState, like this (also in the OnInit method):
ViewState.Add("ProfileImages", ProfileImages);
And then retrieve it before I use the array, like this (in the DoSomething() method):
ProfileImages = (ImageMap[])ViewState["ProfileImages"];
This has the effect that sometimes the array is not null, but the imageMaps in it are still null.
So how do I correctly conserve my variable across page requests?