Click here to Skip to main content
12,396,461 members (36,518 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 20-Jan-13 19:10pm
Comments
   
Just a note: this is not related to static members (not variables, members) at all.
—SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi Cbab,

I think the following sample code helps you.

//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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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.
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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2016
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