TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shiva Nandan
NA
30
0
Static Varible Sharing Problem
Jun 10 2009 3:02 AM
Hai Friends
I have declared a variable outside all the function in an aspx.cs page, like
public partial class StaticVar : System.Web.UI.Page
{
static int a;
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(a.ToString());
}
protected void Button1_Click(object sender, EventArgs e)
{
a = 50;
Response.Write("set 50, a= " + a.ToString());
}
protected void Button2_Click(object sender, EventArgs e)
{
a = 60;
Response.Write("set 60, a= " + a.ToString());
}
protected void Button3_Click(object sender, EventArgs e)
{
Response.Write("a= " + a.ToString());
}
}
The problem is that when more than one user access this page and modifies the variable a, all the users gets the new value for a,
i.e., they loose the value what they had set for a. They get the value that is been set by the last user.
If I remove 'Static' from its declaration, then its value is not available to other functions.
How to solve this problem.
Please help me.
Reply
Answers (
1
)
need help with master pages and wysiwyg editor
downloading multiple file...