Click here to Skip to main content
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 4:39am
Cleops194

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

  Print Answers RSS
0 OriginalGriff 410
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 264
3 BillWoodruff 235
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


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