You have to write these code on Validating event of TextBox.
Private Sub NumericValidation(ByVal sender As Object, ByVal e As CancelEventArgs) Handles textBox1
Dim txtTemp As TextBox
txtTemp = DirectCast(sender, TextBox) 'Explicit type casting of sender to TextBox
If TypeOf txtTemp Is TextBox Then
If IsNumeric(txtTemp.Text) = False Then
MessageBox.Show("Please enter only numeric value.")
txtTemp.Text = String.Empty
txtTemp.Focus()
End If
End If
End Sub
Private Sub NumericValidation(ByVal sender As Object, ByVal e As CancelEventArgs) Handles textBox1
Dim txtTemp As TextBox
txtTemp = DirectCast(sender, TextBox) 'Explicit type casting of sender to TextBox
If TypeOf txtTemp Is TextBox Then
If IsNumeric(txtTemp.Text) = False Then
MessageBox.Show("Please enter only numeric value.")
txtTemp.Text = String.Empty
txtTemp.Focus()
End If
End If
End Sub
No comments:
Post a Comment