simple validation problem

  • Thread starter Thread starter Lars-Erik Aabech
  • Start date Start date
Abul:
Abul Hasan said:
Hello everyone,

I have placed simple validation through ErrorProvider Class on my textBoxes
to check whether ther r empty or not

Error Provider Class check and catches the error but it doesn't stop saving
the record. For instance if I click on any other button on the form it
doesn't stop user from doing so. How can I stop or restrict user to stay in
the textbox prebenting any other button or option to be clicked as long as
there is a valid entry in the textbox.
Hope everyone can understand myu problem

Here is the code for ur reference.


Private Sub txtuId_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtuId.Validating

If txtuId.Text = String.Empty Then

ErrorProvider1.SetError(txtuId, "UserId cannot be left blank")

txtuId.Focus()

Me.ActiveControl = txtuId

e.Cancel = True

Else

ErrorProvider1.SetError(txtuId, String.Empty)

End If

End Sub



Waiting for Quick responce.
Abul Hasan

Two things...

If I'm reading this right you are calling the errorprovider either
way..That's not causing your problem but it doesn't seem like something
you'd want to do.

I took your code and if I click on a button, it will let it fire. However,
I can't click in another textbox. However, if you get rid of the call to
me.ActiveControl and the txtUid.Focus, you can't click on the button or
anywhere else. By default, if you call e.cancel in validating, it won't let
you out of the textbox. You can 'click' on a button for instance, but it
won't do anything. Try taking those two lines of code out and see if that
doesn't fix it for you...
http://www.knowdotnet.com/articles/validation2.html

HTH

Bill
 
Hi Abul,

I tested this code and in my opinion it does everything as it should do.
Are you doing the saving from the same form as this?

I changed the code a little, but that is only because the way we makes them
here on this board.
It are not changes that has to do with your error as far as I can see.

Cor

Private Sub txtuId_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtuId.Validating
If txtuId.Text = "" Then
ErrorProvider1.SetError(txtuId, "UserId cannot be left blank")
Cancel = True
Else
ErrorProvider1.SetError(txtuId, "")
End If
End Sub
 
Hi Abdul,
relax man i know lil bit of programming ;)

But others can read this also who do not that much.
(Besides the ones who will tell me it to tickle me)

:-))

I had no doubt that you would see this.

Cor
 
Hello everyone,

I have placed simple validation through ErrorProvider Class on my textBoxes
to check whether ther r empty or not

Error Provider Class check and catches the error but it doesn't stop saving
the record. For instance if I click on any other button on the form it
doesn't stop user from doing so. How can I stop or restrict user to stay in
the textbox prebenting any other button or option to be clicked as long as
there is a valid entry in the textbox.
Hope everyone can understand myu problem

Here is the code for ur reference.


Private Sub txtuId_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtuId.Validating

If txtuId.Text = String.Empty Then

ErrorProvider1.SetError(txtuId, "UserId cannot be left blank")

txtuId.Focus()

Me.ActiveControl = txtuId

e.Cancel = True

Else

ErrorProvider1.SetError(txtuId, String.Empty)

End If

End Sub



Waiting for Quick responce.
Abul Hasan
 
Back
Top