I have web form in which I have to make sure that ‘SUBMIT’ button is being clicked no more than 3 times. I have some logic in the form which restricts the user to enter anything after 3 failed attempts.
This is my logic, but I know this is not right:
protected void btnSubmit_Click(object sender, EventArgs e)
{
int count = 0;
count++;
if (count <= 3)
{
Function1();
}
else
MessageBox("You submitted your information more than 3 times.");
}
This wont work because count will be ZERO every time the page refreshes up.
Save the variable in the
ViewStateof the page. Initialize its value on the first load of the page:On the
Button.Clickevent increase the value of the count variable :