ASP.NET variable scope

Does anybody know how I can use variables in the whole ASP.NET program? page_load seams to clear the data stored in the variables. I have an array with data in it, and it has to keep all it's information.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Declare variable in Global.asax in the Application_OnStart() block. That's if the variable is the same for all users.

If different users hold their own variables for the session then you need to use session state.

The following for more info:

A little more information and I may be able to give you some code
paing0dAuthor Commented:
Let me explain my webprogram.
First users have to login.
When the succesfully logged in they should answer bout 15 questions. When done they should be able to click the next button, and then there are 15 more questions etc. The can answer those questions with 4 possibilitys. Like easy, moderate, hard. A variable needs to be decleared to store the users checkboxes.value for each tab. So you would have an array like:

array(5,15) as integer 'x='tab' number y=question number

if a certain answer is checked then there should be a number in the array. So if the first question is answered with easy then array(1,1) = 1 if it's moderate then array(1,1) = 2 etc

The questions are in a textfile. I fill an array with all the information in page_load (don't think that's a good idea though).

I made a variable page_number. This is the current page number. So i can easily set the new questions when the next or previous buttons is pressed.

After completing all the questions, a new part is made visible. The questions part will be made invisible. When you've finished the last part the results should be mailed to a number of persons.

ps. Login part is also made invisible after a succesfull login. Then Question part will be made visible. (put those 3 parts on panels so it's easily to put it invisible).

OK! Thanks, that helps.

It looks like the simplest way to handle this is to use multiple panels on one page to handle the different sections of the form. This way you can handle all the data within a single form and can be handled by a single submit button and data processing routine.

These two tutorials should help:

Hope that solves the problem.
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

paing0dAuthor Commented:
Sorry for the late reaction. Was very busy for the last couple of days. I don't get it :( When i declare something and when i want to use it, it get clears by the page_load
Public variables don't seem to store the data well. Found a solution but that's not the right solution. Application("array") = array works very well, but it's not a multiple users system. Session("aray") = array doesn't work at all, and me.viewstate("array") = array doesn't work either. Can someone help me please. Tell me what to do. Need to store variables that work in the whole program

Thanks in advance,

If you've experimented with Session, Application & ViewState and are still not satisfied, perhaps you should look at using a small database or XML file.

What constraints do you have @ your web host?
paing0dAuthor Commented:
I don't know but i try to find it out.
So the only option is to save files to the server?
I might be able to say better if you actually made a code sample available so I can see exactly how you need to use the stored data.

And you haven't made it clear whether you are concerned about losing the data for the questions on each page_load, or the answers...

If you make this clear, and provide a sample of what you are doing I will be able to post code to help you...
paing0dAuthor Commented:
cookieless="true" solves the whole problem :p
if you don't know where that is then open the Web.config and there should be something called
<sessionState ....
cookieless="false" -> change it to cookieless="true"

thanks all :)
Bob LearnedCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


Please leave any comments here within the next seven days.


EE Cleanup Volunteer
paing0dAuthor Commented:
I guess I solved my question myself :) What to do?

PAQed, with refund (50)

Friendly Neighbourhood Community Support Admin

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.