Click here to Skip to main content
13,558,063 members
Rate this:
Please Sign up or sign in to vote.
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?
Posted 14-Mar-13 3:39am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180515.1 | Last Updated 14 Mar 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100