Here, we will see How to disable button click in ASP.NET.

For example:

Create a web form having a login and password field and a login button. If login and password goes wrong for three times then disable the login button and give the message "Your Account is Blocked"

Double click on the Button control and add the following code.

VB code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

If Not (TextBox1.Text = "abc" AndAlso TextBox2.Text = "xyz") Then

If ViewState("ec") IsNot Nothing Then

count = Convert.ToInt32(ViewState("ec"))

End If

count += 1

ViewState("ec") = count

Label1.Text = "count is " & count

If count = 3 Then

Button1.Enabled = False

Label1.Text = "Your Account is blocked"

End If

End If

End Sub