473,386 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 1262
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
3
by: Marc Llenas | last post by:
Hi there, I'm stuck on a validation function for a form and I cannot figure out what the problem is. The page is in ASP. Any ideas? The function being called is: <script...
3
by: Kent Ogletree | last post by:
I am porting a Java XML Validation class over to C# and I am having a problem finding exactly what I need to acomplish the task. First I need to test for well formedness. I know this is usually...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
3
by: john morales | last post by:
Hi guys, I have a problem and i know there must be a solution for this as it is such a basic common practice in asp.net development. Scenario: i have many webforms in a site, most with two...
2
by: SimonH | last post by:
Hi All, I'm having problems getting a custom validator to work. I'm hoping someone could perhaps notice what I've missed. I only want to provide a server side validation method. The problem is...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
9
by: Bill Long | last post by:
I have a control that simply displays a list of links. Following one of the links doesn't post back or redirect to another page, it simply hides the current panel and shows the one you selected......
3
by: Eric Lilja | last post by:
Hello, this is an xml-file with a nested DTD. It validates, test-1- with-dtd.xml: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE persons > <persons> <person name="Eric Lilja" /> </persons>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.