Click here to Skip to main content
15,906,574 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Sorry about the subject I didn't really know how to explain this in a few words!

On a button I am looking to check if it has already been clicked since the application has been loaded.

Basically if clicked for the first time make someone enter there details if they click the same button again during the application being started I want the program to ask if they would like to edit there details rather than throwing up the same initial enter details page.

Could I use a variable and increment it in a loop so that if the variable is more than 0 do this if it is 0 then it must be there first visit to this section. Would something like that work or is there a totaly different way I am overlooking?

Thanks in advance
Posted
Comments
RakeshMeena 9-Jun-11 6:14am    
What if the user modify the details and then click the button again? Do you still want to show the message?
DanHodgson88 9-Jun-11 6:20am    
Yes the idea is a nav bar with a details section, On the first click they will be sent to enter there details which once submited is sent to "Overview" page. The overview page will have the ability to edit which will then direct them back to the original details section where they can alter anything they need to. If that makes sense?

Easiest way: Use the button Tag field, and set it to a bool value: FirstTime is true for example. Then in the click event:

private void button1_Click(object sender, EventArgs e)
    {
    Button b = sender as Button;
    if (b != null && (bool) b.Tag)
        {
        // It's the first time.
        b.Tag = false;
        }
    }
 
Share this answer
 
Comments
RakeshMeena 9-Jun-11 6:16am    
My 5!
DanHodgson88 9-Jun-11 6:17am    
Thanks very much 5+ :)
OriginalGriff 9-Jun-11 6:19am    
Welcome!
Sergey Alexandrovich Kryukov 9-Jun-11 11:54am    
It's simple enough, my 5.

If you want to read something really interesting on this topic (or rather funny), please see my answer and my article.
This solution is absolutely universal :-)
--SA
A very exotic but extremely universal solution: see my article "Wish You Were Here… Only Once"[^].

—SA
 
Share this answer
 
v2
Comments
BobJanova 9-Jun-11 12:14pm    
Hehe ... that is massively over the top for most practical situations, but it's brilliant all the same.
DanHodgson88 9-Jun-11 13:12pm    
lol agreed 5+ but maybe a bit to much for me!!
Sergey Alexandrovich Kryukov 9-Jun-11 13:23pm    
Thank you very much, Bob, Dan.
I planned this article almost like a joke, but gradually got a challenge to make it really easy to use and fool-proof, I think -- succeeded. The usage is one line...
--SA
Hi DanHodgson88,

You can make a Global Boolean variable and using the Button_Click event handler you can check like this :

public static bool EvenClicks = true;

private void button1_Click(object sender, EventArgs e)
{
    EvenClicks = !EvenClicks;
    if (EvenClicks)
    {
        // add the code for clicking twice or for even number of clicks
    }
    else
    {
        // add the code for clicking once or for odd number of clicks
    }
}


I hope this help,
:)
 
Share this answer
 
Comments
DanHodgson88 9-Jun-11 6:18am    
cheers for the reply wasn't quite what I was looking for, however that will come handy on another button :D
Sergey Alexandrovich Kryukov 9-Jun-11 11:53am    
I voted 4 for using static and calling it "global". If you think of it, you will see that static is worse and non-static will work as well (I can explain).

If you want to read something really interesting on this topic (or rather funny), please see my answer and my article.
This solution is absolutely universal.
--SA
u can simply perform those type of operations by using static variables

for first time user clicks on button

set static variable to some value

for second time increment the value of static variable

basing on that we can specify a if condition to per form operation

if(i%2!=0)
op1;
else if (i%2==0)
op2;
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900