Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have implemented one small web application. In my application i have used the static variables to store the data globally. I am facing the problem with the static variables. I am opening my application in two different browsers. I got the problem here the static variables are storing the value globally for different browsers. How can i solve this issue. Is there any better way to convert the static variables to the sessions.
Posted
Comments
Sergey Alexandrovich Kryukov 21-Jan-13 1:52am    
Just a note: this is not related to static members (not variables, members) at all.
—SA

Hi Cbab,

I think the following sample code helps you.

C#
//create a session variable and store the value you need to(Any datatype can be stored)
Session["sessionname"] = TheValueToBeStored;

//extract the value from the session to the variable of the corresponding type.
short Var_name= Convert.ToInt16(Session["sessionname"]);


Thank you....
Sijo
 
Share this answer
 
I modified static variable to normal variable, and i stored the variable into the session. If we want to get the data of the variable we can get the data from the session.

Note:
The session is storing the address of the variable. If we change the value of the variable automatically the value of the session is also change.
 
Share this answer
 
Looking at the problem statement it looks like you need some variables to behave as if they are static from your applications perspective. Changing the variables to session variables will let you reuse the variable from same session. If you need to make the variable value available from all your application then you will need to use Application object./code>object.
C#
Application["key"] = value;

here is a small link to understand the logic behind doing this.

A Beginner's Tutorial on ASP.NET State Management[^]

Let me know if I understood it incorrectly and I will try to refine my answer.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900