0

Hi. i need to count the number of times a button has been clicked in C# windows application. for asp websites i know how to do it using viewstates but i dont know how to do it with windows form application. Any help will be greatly appreciated.

3
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by kirtee2209
0

Yee, look this code:

int intClicks;
        private void button1_Click(object sender, EventArgs e)
        {
            intClicks++;
            MessageBox.Show("button has been clicked " + intClicks + (intClicks == 1 ? " time." : " times."));
        }
0
private void btnlogin_Click(object sender, EventArgs e)
        {
            
            count++;
            if (count <= 3)
            {
                login();
            }
            else
            {
                MessageBox.Show("3");
            }
        }

this is what i was doing!! and i found the error! the "int count = 0;" was setting count to zero outputing 1 every time! so ive removed it and added it as a global variable. But still thanks a lot for replying!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.