Reputation: 991
I have a TextBox, The situation is that when a user leaves it empty, OK button is disabled. If user types in a value of duration based on days, the button gets enabled.
The problem is: let's say the user clicks on text box, types in : 100, and he realizes that he made a mistake, he erase that value and tries to start filling some other textboxes and come back again afterwards, at this level at the time user clicks on other part of form, the value becoems 0 autoamtically and Ok button is Enabled Now.
How can I avoid this?
Private Sub txtMembershipDuration_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMembershipDuration.TextChanged
If txtMembershipDuration.Text = "" Then
btnOK.Enabled = False
End If End Sub
Also, how can I control that auttomatic 0?
Upvotes: 0
Views: 148
Reputation: 109037
You could check for "0" if it's not a valid value
Private Sub txtMembershipDuration_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtMembershipDuration.TextChanged
If txtMembershipDuration.Text = "" OrElse
txtMembershipDuration.Text = "0" Then
btnOK.Enabled = False
End If
End Sub
Upvotes: 0
Reputation: 3299
Use a TryParse
on your check, and make sure it's greater than 0, instead of checking if it's "".
Link: TryParse
Upvotes: 1