472,127 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

simple validation problem

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
Nov 20 '05 #1
8 1215
Try using Validation Controls instead, I believe they cancel events if
triggered.
You can find information on using them here:
http://msdn.microsoft.com/library/de...torControl.asp

HTH,
Lars-Erik
"Abul Hasan" <st******@yahoo.co.uk> wrote in message
news:OR**************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #2
Abul:
"Abul Hasan" <st******@yahoo.co.uk> wrote in message
news:OR**************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #3
Thanks a lot

solved my problem.

Abul Hasan Lakhani. MCP

"Abul Hasan" <st******@yahoo.co.uk> wrote in message
news:OR**************@tk2msftngp13.phx.gbl...
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

Nov 20 '05 #4
Cor
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

Nov 20 '05 #5
Cor
cancel = e.cancel
Nov 20 '05 #6
hey cor

relax man i know lil bit of programming ;)

Abul.

"Cor" <no*@non.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
cancel = e.cancel

Nov 20 '05 #7
Cor
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
Nov 20 '05 #8
* "Abul Hasan" <st******@yahoo.co.uk> scripsit:
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


Set the controls' 'Enabled' property to 'False'.

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by Stefan Richter | last post: by
3 posts views Thread by Marc Llenas | last post: by
3 posts views Thread by Kent Ogletree | last post: by
51 posts views Thread by Alan | last post: by
3 posts views Thread by john morales | last post: by
2 posts views Thread by SimonH | last post: by
18 posts views Thread by Q. John Chen | last post: by
9 posts views Thread by Bill Long | last post: by
3 posts views Thread by Eric Lilja | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.