473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

C# web application remember integer values

This is my code.. but the literal keeps showing 1.
Could someone help me? thank you!

public partial class _Default : System.Web.UI.Page
{
int x = 0;

protected void Page_Load(object sender, EventArgs e)
{


}

protected void Button1_Click(object sender, EventArgs e)
{

x += 1;
Literal1.Text = Convert.ToString(x);

}
Oct 14 '08 #1
2 993
PRR
750 Expert 512MB
This is my code.. but the literal keeps showing 1.
Could someone help me? thank you!

public partial class _Default : System.Web.UI.Page
{
int x = 0;

protected void Page_Load(object sender, EventArgs e)
{


}

protected void Button1_Click(object sender, EventArgs e)
{

x += 1;
Literal1.Text = Convert.ToString(x);

}
use static int x=0;
for variables that should be independent of objects use static...
Also you could use Cache
Expand|Select|Wrap|Line Numbers
  1. if (Cache["a"] == null)
  2.         {
  3.             Cache["a"] = 0;
  4.         }
  5.         Cache["a"] = (int)Cache["a"]+1;
  6.         i = (int)Cache["a"] ;
  7.  
  8.         Button1.Text = Convert.ToString(i);
  9.  
  10. //and in page load 
  11. if (!IsPostBack)
  12.         {
  13.  
  14.             Cache["a"] = 0;
  15.         } 
  16.  
Oct 14 '08 #2
Thanks, i fixed the problem by using sessions :)
Oct 14 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mo | last post by:
Hi, I have a webform which has vb.net code behind it and I would like it to submit the entries in the fields into a sql server db using a stored procedure. I have a central .vb file in my...
1
by: Trancedified | last post by:
Hello, I read through this thread regarding FindWindowEx vs. EnumChildWindows: http://www.xtremevbtalk.com/showthread.php?t=130418 It looks like it was done in VB6, can this be done in...
1
by: RSH | last post by:
Hi, I am deep into creating a VB .Net application that basically creates SQL Server versions of our Access databases and copies over all the data. I Extracted the VB DTS script and brought it...
0
by: Anup Daware | last post by:
Hi All, I am facing this very weird issue, for every server request my control is redirecting to the login page and again coming back to the actual page from where the request was initiated when I...
0
by: Anup Daware | last post by:
Hi All, I am facing this very weird issue, for every server request my control is redirecting to the login page and again coming back to the actual page from where the request was initiated when I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.