473,396 Members | 1,666 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,396 software developers and data experts.

how to count the number of button clicks?

How do you count the number of button clicks?
Expand|Select|Wrap|Line Numbers
  1. int count;
  2. if (Label1.Text == "")
  3. {
  4.   Label1.Text = (count + 1).ToString();
  5.   count++;
  6.  
  7. }
  8. else
  9. {
  10.   count = Convert.ToInt32(Label1.Text);
  11.   Label1.Text = (count + 1).ToString();
  12. }
May 29 '12 #1

✓ answered by Frinavale

You could retrieve the count form the label using the Int32.TryParse method and go from there:
Expand|Select|Wrap|Line Numbers
  1. int count;
  2. Int32.TryParse(Label1.Text, out count);
  3. count++;
  4. Label1.Text = count.ToString();
  5.  

4 2476
the count should be declared globally............
May 29 '12 #2
Frinavale
9,735 Expert Mod 8TB
You could retrieve the count form the label using the Int32.TryParse method and go from there:
Expand|Select|Wrap|Line Numbers
  1. int count;
  2. Int32.TryParse(Label1.Text, out count);
  3. count++;
  4. Label1.Text = count.ToString();
  5.  
May 29 '12 #3
ya...thank u,i will try finvarle
May 31 '12 #4
sialon
3
You can create a table in a database id and count
for button
Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.  
  4.         try
  5.         {
  6.             if (Session["mode"] == "true")
  7.             {
  8.  
  9.                 SqlConnection con = new SqlConnection("");
  10.                 SqlCommand cmd = new SqlCommand("select * from TB_Count", con);
  11.                 con.Open();
  12.                 SqlDataReader sdr = cmd.ExecuteReader();
  13.                 sdr.Read();
  14.                 int super = int.Parse(sdr["count"].ToString());
  15.                 super++;
  16.                 string str = "update TB_Count set Count='" + super + "'";
  17.                 con.Close();
  18.                 SqlConnection con1 = new SqlConnection(conn);
  19.                 SqlCommand cmd1 = new SqlCommand(str, con1);
  20.                 con1.Open();
  21.                 cmd1.ExecuteNonQuery();
  22.                 con1.Close();
  23.                 Label2.Text = " NumberDownloads:" + super;
  24.                 Response.Redirect(" address file");
  25.             }
  26.             else
  27.             {
  28.                 Button1.Visible = false;
  29.                 Button2.Visible = true;
  30.                 Label4.Visible = true;
  31.             }
  32.  
  33.  
for pageload
Expand|Select|Wrap|Line Numbers
  1. SqlConnection con = new SqlConnection(conn);
  2.                 SqlCommand cmd = new SqlCommand("select * from TB_Count", con);
  3.                 con.Open();
  4.                SqlDataReader sdr = cmd.ExecuteReader();
  5.                 sdr.Read();
  6.                int super = int.Parse(sdr["Count"].ToString());
  7.                 con.Close();
  8.                Label2.Text = "NumberDownloads:" + super;
  9.  
  10.  
Jun 6 '12 #5

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

Similar topics

1
by: vic | last post by:
Hello, Dean Try this: select distinct c1, c2 into #tmp_1 from t1 select count(*) as cnt from #tmp_1 drop table #tmp_1 With best regards.
0
by: DataFreakFromUtah | last post by:
Hello! No question here, just a procedure for the archive. Search critera: count records imported count data imported count number of rows imported count number of records imported record import...
2
by: S. Justin Gengo | last post by:
I'm thinking of building a component that, when dropped onto a .aspx page, will intercept all form post back button clicks (maybe even all postback events triggered by a .net control) using the...
1
by: tranky | last post by:
hi, only one information,please... how to count number of anonymous online users? I use ASP.NET 2.0 thank u tranky
0
by: Bill | last post by:
Hi, I was curious as to what experienced folks are doing as far as TDD'ing hooking up events - in particular a button click - to the presenter. I've seen examples (Rhinomock docs) hooking up a...
11
by: Mack | last post by:
Hi all, I want to write a program to count number of bits set in a number. The condition is we should not loop through each bit to find whether its set or not. Thanks in advance, -Mukesh
9
by: larryimic | last post by:
I have created a Access production database that records good parts and bad parts to a table thru querys using macros and command buttons on a form. A report (part label) is printed each time a...
2
by: mfaisalwarraich | last post by:
Hi Everybody, I am using the following code to get the recordset of an external database. Dim dbPatients As Database Dim rsCountPatients As Recordset ' to count number of...
5
by: jambonjamasb | last post by:
I am wanting to create a report that summarises the number of items within a date range. For example I have a FIELD called System_Change. This is a drop down COMBOBOX that uses words like unix,...
1
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.