Click here to Skip to main content
11,719,903 members (87,474 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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?
Posted 14-Mar-13 3:39am
Cleops225

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 1,869
1 OriginalGriff 770
2 F-ES Sitecore 640
3 Maciej Los 609
4 Richard MacCutchan 540


Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 14 Mar 2013
Copyright © CodeProject, 1999-2015
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