Validating textbox

  • Thread starter Thread starter Rajesh
  • Start date Start date
R

Rajesh

I had created one application in .net.Now want to check whether any
user enters correct string or not.If any user entering an incorrect
string display an error msg.How can i do this validation.In numeich it
works fine.But in String it's not working .
 
How are you trying to validate? Are you writing code? Are you using a
Validation Control?

What is the error you are getting?
 
Rajesh said:
I had created one application in .net.Now want to check whether any
user enters correct string or not.If any user entering an incorrect
string display an error msg.How can i do this validation.In numeich it
works fine.But in String it's not working .

Place an ErrorProvider component on the form and add this code:

\\\
Imports System.ComponentModel
..
..
..
Private Sub TextBox1_Validating( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles TextBox1.Validating
Dim SourceControl As TextBox = DirectCast(sender, TextBox)
Dim ErrorText As String
Try
Dim i As Integer = Integer.Parse(SourceControl.Text)
Catch
ErrorText = "Value must be an integer."
Finally
Me.ErrorProvider1.SetError( _
SourceControl, _
ErrorText _
)
End Try
End Sub
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top