I have an ASP.NET web forms application where the user opens up an image on an ImageButton control. I set a global int variable "counter" to zero outside before defining methods. Every time the user clicks on the ImageButton control the "counter" is supposed to increase by one. The OnClick method associated with the ImageButton is firing, but I think the "counter" is being reset after each click. I know this because only the if branch in Image_Click is being executed. How can I make sure that the updated value of "counter" is remembered for each click?
Here is .aspx code for ImageButton:
<asp:ImageButton ID="pic" runat="server" OnClick="Image_Click" />
Here is c# code for Image_Click:
public int numClick++;
protected void Image_Click(object sender, ImageClickEventArgs e)
{
numClick++;
if (numClick % 2 == 1)
{
pos1x = e.X;
pos1y = e.Y;
labelarea.Text = " " + pos1x;
}
else if (numClick % 2 == 0)
{
pos2x = e.X;
pos2y = e.Y;
distx = Math.Abs(pos2x - pos1x);
disty = Math.Abs(pos2y - pos1y);
redistx = (int)(Math.Ceiling((float)(distx / (zoom * Math.Floor(dpiX / 4.0)))));
redisty = (int)(Math.Ceiling((float)(disty / (zoom * Math.Floor(dpiY / 4.0)))));
if (mode == 1)
{
if (distx >= disty)
{
lengthlabel.Text = "Length: " + redistx;
total += redistx;
}
else
{
lengthlabel.Text = "Length: " + redisty;
total += redisty;
}
labeltotal.Text = "Total: " + total;
}
}
}