I'm building a web application i Visual Studio using C#.
I need to check if it is the first time a button is clicked. If it is the first time I want to pick variables from one place. If it is not the first time I want to pick variable from another place.
I tried using a class Click
namespace myProject
{
public class Click
{
public int buttonclick = 0;
}
}
{
public class Click
{
public int buttonclick = 0;
}
}
In button click:
Click.buttonclick++;
if (Click.buttonclick == 1)
{
MessageBox.Show("First click");
}
else
MessageBox.Show("Other clicks");
if (Click.buttonclick == 1)
{
MessageBox.Show("First click");
}
else
MessageBox.Show("Other clicks");
This code works the first time the web form is visited. If I go to another page and then return to this page the variable does not resets to zero. I need the variable to reset to zero every time page is visited. Is there another solution for this?
Jignesh TrivediPosted May 8, 2014, 1:25 AM
hi,
you are developing web application so you can also use javascript instead of server side code.
var p= 0;
if ("#button").click(function() {
if(p>0)
{
alert('other click');
}
else
{
alert('first click');
}
p=p+1;
});
hope this will help you.
VulpesPosted May 7, 2014, 6:08 PM