paing0d
asked on
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.
Tony
Tony
ASKER
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.
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.
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.
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.
ASKER
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
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
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?
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?
ASKER
I don't know but i try to find it out.
So the only option is to save files to the server?
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...
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...
ASKER
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 :)
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 :)
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
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
ASKER
I guess I solved my question myself :) What to do?
Tony
Tony
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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