Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ASP.NET variable scope

Posted on 2003-03-20
11
Medium Priority
?
290 Views
Last Modified: 2010-08-05
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.

Tony
0
Comment
Question by:paing0d
11 Comments
 

Expert Comment

by:jachin
ID: 8214907
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:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconsessionstate.asp

A little more information and I may be able to give you some code
0
 

Author Comment

by:paing0d
ID: 8216217
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).

Tony.
0
 

Expert Comment

by:jachin
ID: 8221680
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:

http://www.aspnet101.com/aspnet101/aspnet/codesample.aspx?code=pnlDisplay
http://www.aspalliance.com/articles/panels.aspx

Hope that solves the problem.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

Author Comment

by:paing0d
ID: 8255503
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,
   Tony
0
 

Expert Comment

by:jachin
ID: 8256294
Tony,

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?
0
 

Author Comment

by:paing0d
ID: 8259470
I don't know but i try to find it out.
So the only option is to save files to the server?
0
 

Expert Comment

by:jachin
ID: 8264236
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...
0
 

Author Comment

by:paing0d
ID: 9548079
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 :)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 9688045
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:

PAQ/Refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0
 

Author Comment

by:paing0d
ID: 9707769
I guess I solved my question myself :) What to do?

Tony
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 9735296
PAQed, with refund (50)

Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Integration Management Part 2
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question