473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Validate Multiple Text Boxes?

I have a form that has about 10 text boxes on it, they all have to be filled
out before submitting is there a quick way to make sure that none are null
or do I have to call out each textbox? Say something like textbox1 through
textbox10? Thanks
Nov 20 '05 #1
9 6642
Create a handler for the first textbox by double clicking on it,

Use the error provider and validated event. See the documentation for
examples.


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"B-Dog" <bd***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have a form that has about 10 text boxes on it, they all have to be filled out before submitting is there a quick way to make sure that none are null
or do I have to call out each textbox? Say something like textbox1 through textbox10? Thanks

Nov 20 '05 #2
Sorry, scrub the first line of my post above.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:O8****************@tk2msftngp13.phx.gbl...
Create a handler for the first textbox by double clicking on it,

Use the error provider and validated event. See the documentation for
examples.


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"B-Dog" <bd***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have a form that has about 10 text boxes on it, they all have to be

filled
out before submitting is there a quick way to make sure that none are null or do I have to call out each textbox? Say something like textbox1

through
textbox10? Thanks


Nov 20 '05 #3
Thanks, OHM. I see if I can find an example.

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:#9**************@tk2msftngp13.phx.gbl...
Sorry, scrub the first line of my post above.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:O8****************@tk2msftngp13.phx.gbl...
Create a handler for the first textbox by double clicking on it,

Use the error provider and validated event. See the documentation for
examples.


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"B-Dog" <bd***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have a form that has about 10 text boxes on it, they all have to be

filled
out before submitting is there a quick way to make sure that none are null or do I have to call out each textbox? Say something like textbox1

through
textbox10? Thanks



Nov 20 '05 #4
B-Dog,
In addition to adding handlers for the Validating event that Terry (OHM)
suggested.

I got the following tip from "Windows Forms Programming in C#" by Chris
Sells, from Addison Wesley.

Within your "Accept" button click handler (the "save" button) process each
control that CausesValidation to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesValidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.None
Exit For
End If
End If
Next

Note this version does not validate controls nested within other container
controls, such as GroupBoxes...

The above code will cause the Validating event for each of your controls to
be raised, ensuring that all the controls get validated, before the dialog
is closed or the data is saved...

Hope this helps
Jay

"B-Dog" <bd***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have a form that has about 10 text boxes on it, they all have to be filled out before submitting is there a quick way to make sure that none are null
or do I have to call out each textbox? Say something like textbox1 through textbox10? Thanks

Nov 20 '05 #5
I couldn't find exactly how to do it, I'm very new at VB but this is how I
did it temporarily until I figured out the other way. I heard using the
validated event was the way to go cause it would show an icon next to the
field that needs attention or something. I just don't know how to implememt
it. I have textbox2 - 8

check to make sure all is filled out

Dim c As Control

For Each c In Me.Controls

If TypeOf c Is TextBox Then

If CType(c, TextBox).Text = "" Then

Exit Sub

End If

End If

Next

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:#x*************@TK2MSFTNGP11.phx.gbl...
B-Dog,
In addition to adding handlers for the Validating event that Terry (OHM)
suggested.

I got the following tip from "Windows Forms Programming in C#" by Chris
Sells, from Addison Wesley.

Within your "Accept" button click handler (the "save" button) process each
control that CausesValidation to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesValidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.None
Exit For
End If
End If
Next

Note this version does not validate controls nested within other container
controls, such as GroupBoxes...

The above code will cause the Validating event for each of your controls to be raised, ensuring that all the controls get validated, before the dialog
is closed or the data is saved...

Hope this helps
Jay

"B-Dog" <bd***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have a form that has about 10 text boxes on it, they all have to be

filled
out before submitting is there a quick way to make sure that none are null or do I have to call out each textbox? Say something like textbox1

through
textbox10? Thanks


Nov 20 '05 #6

"B-Dog" <bd***@hotmail.com> wrote in message
news:OT*************@TK2MSFTNGP11.phx.gbl...
I couldn't find exactly how to do it, I'm very new at VB but this is how I
did it temporarily until I figured out the other way. I heard using the
validated event was the way to go cause it would show an icon next to the
field that needs attention or something. I just don't know how to implememt it. I have textbox2 - 8

check to make sure all is filled out

Dim c As Control

For Each c In Me.Controls

If TypeOf c Is TextBox Then

If CType(c, TextBox).Text = "" Then

Exit Sub

End If

End If

Next

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:#x*************@TK2MSFTNGP11.phx.gbl...
B-Dog,
In addition to adding handlers for the Validating event that Terry (OHM)
suggested.

I got the following tip from "Windows Forms Programming in C#" by Chris
Sells, from Addison Wesley.

Within your "Accept" button click handler (the "save" button) process each
control that CausesValidation to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesValidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.None
Exit For
End If
End If
Next

Note this version does not validate controls nested within other container controls, such as GroupBoxes...

The above code will cause the Validating event for each of your controls

to
be raised, ensuring that all the controls get validated, before the dialog is closed or the data is saved...

Hope this helps
Jay

"B-Dog" <bd***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have a form that has about 10 text boxes on it, they all have to be

filled
out before submitting is there a quick way to make sure that none are

null or do I have to call out each textbox? Say something like textbox1

through
textbox10? Thanks



Nov 20 '05 #7
B-Dog,
Its "easier" to use the Validating event for TextBox, Validating is
inherited from Control, so all controls have a Validating event.

For details on the Validating event see:

http://msdn.microsoft.com/library/de...atingtopic.asp

In your case you can use something like for all 8 text boxes:

Private Sub textBox1_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles
textBox1.Validating

If textBox1.Text = "" Then
' Cancel the event and select the text to be corrected by the user.
e.Cancel = True
End If
End Sub

Alternatively you can have all 8 use one routine.

Private Sub textBox_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles
textBox1.Validating, TextBox2.Validating, TextBox3.Validating,
TextBox4.Validating

Dim txt As TextBox = DirectCast(sender, TextBox)

If txt.Text = "" Then
' Cancel the event and select the text to be corrected by the user.
e.Cancel = True
End If
End Sub

Note the above link using the ErrorProvider control to display errors to the
user.

http://msdn.microsoft.com/library/de...ClassTopic.asp

Hope this helps
Jay

"B-Dog" <bd***@hotmail.com> wrote in message
news:OT*************@TK2MSFTNGP11.phx.gbl...
I couldn't find exactly how to do it, I'm very new at VB but this is how I
did it temporarily until I figured out the other way. I heard using the
validated event was the way to go cause it would show an icon next to the
field that needs attention or something. I just don't know how to implememt it. I have textbox2 - 8

check to make sure all is filled out

Dim c As Control

For Each c In Me.Controls

If TypeOf c Is TextBox Then

If CType(c, TextBox).Text = "" Then

Exit Sub

End If

End If

Next

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:#x*************@TK2MSFTNGP11.phx.gbl...
B-Dog,
In addition to adding handlers for the Validating event that Terry (OHM)
suggested.

I got the following tip from "Windows Forms Programming in C#" by Chris
Sells, from Addison Wesley.

Within your "Accept" button click handler (the "save" button) process each
control that CausesValidation to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesValidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.None
Exit For
End If
End If
Next

Note this version does not validate controls nested within other container controls, such as GroupBoxes...

The above code will cause the Validating event for each of your controls

to
be raised, ensuring that all the controls get validated, before the dialog is closed or the data is saved...

Hope this helps
Jay

"B-Dog" <bd***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have a form that has about 10 text boxes on it, they all have to be

filled
out before submitting is there a quick way to make sure that none are

null or do I have to call out each textbox? Say something like textbox1

through
textbox10? Thanks



Nov 20 '05 #8
Here is the pattern I follow...

Drag an ErrorProvider control from toolbox onto form. (this gives you the
red icon beside the control(s) that is not valid)
' form level variable
Private _error1 As Boolean

Private Sub txtLName_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtLName.Validating
Validate_LName()
End Sub

Private Sub Validate_LName()
If txtLName.Text = "" Then
ErrorProvider1.SetError(txtLName, "Required field")
_error1 = True

Else
ErrorProvider1.SetError(txtLName, "")
' don't set _error1=false, cause other validators may have set
it somewhere else...
End If
End Sub

'^^^ repeat for each control you want to validate

Private Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAccept.Click
Dim myNewhire As New ePCO.NewHireDetails

' assume everything on form is Ok...
_error1 = False

' validate everything again (some control may have never gotten
focus)
Validate_LName()
'^^^repeat for each control you want to validate

'if found an error abort...
If _error1 Then Exit Sub

' save...
End Sub

HTH,
Greg

"B-Dog" <bd***@hotmail.com> wrote in message
news:OT*************@TK2MSFTNGP11.phx.gbl...
I couldn't find exactly how to do it, I'm very new at VB but this is how I
did it temporarily until I figured out the other way. I heard using the
validated event was the way to go cause it would show an icon next to the
field that needs attention or something. I just don't know how to implememt it. I have textbox2 - 8

check to make sure all is filled out

Dim c As Control

For Each c In Me.Controls

If TypeOf c Is TextBox Then

If CType(c, TextBox).Text = "" Then

Exit Sub

End If

End If

Next

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:#x*************@TK2MSFTNGP11.phx.gbl...
B-Dog,
In addition to adding handlers for the Validating event that Terry (OHM)
suggested.

I got the following tip from "Windows Forms Programming in C#" by Chris
Sells, from Addison Wesley.

Within your "Accept" button click handler (the "save" button) process each
control that CausesValidation to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesValidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.None
Exit For
End If
End If
Next

Note this version does not validate controls nested within other container controls, such as GroupBoxes...

The above code will cause the Validating event for each of your controls

to
be raised, ensuring that all the controls get validated, before the dialog is closed or the data is saved...

Hope this helps
Jay

"B-Dog" <bd***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have a form that has about 10 text boxes on it, they all have to be

filled
out before submitting is there a quick way to make sure that none are

null or do I have to call out each textbox? Say something like textbox1

through
textbox10? Thanks



Nov 20 '05 #9
Thanks, guys that worked good, like the error provider, just what I was
looking for, cool feature.
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...
Here is the pattern I follow...

Drag an ErrorProvider control from toolbox onto form. (this gives you the
red icon beside the control(s) that is not valid)
' form level variable
Private _error1 As Boolean

Private Sub txtLName_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtLName.Validating
Validate_LName()
End Sub

Private Sub Validate_LName()
If txtLName.Text = "" Then
ErrorProvider1.SetError(txtLName, "Required field")
_error1 = True

Else
ErrorProvider1.SetError(txtLName, "")
' don't set _error1=false, cause other validators may have set
it somewhere else...
End If
End Sub

'^^^ repeat for each control you want to validate

Private Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAccept.Click
Dim myNewhire As New ePCO.NewHireDetails

' assume everything on form is Ok...
_error1 = False

' validate everything again (some control may have never gotten
focus)
Validate_LName()
'^^^repeat for each control you want to validate

'if found an error abort...
If _error1 Then Exit Sub

' save...
End Sub

HTH,
Greg

"B-Dog" <bd***@hotmail.com> wrote in message
news:OT*************@TK2MSFTNGP11.phx.gbl...
I couldn't find exactly how to do it, I'm very new at VB but this is how I
did it temporarily until I figured out the other way. I heard using the
validated event was the way to go cause it would show an icon next to the field that needs attention or something. I just don't know how to

implememt
it. I have textbox2 - 8

check to make sure all is filled out

Dim c As Control

For Each c In Me.Controls

If TypeOf c Is TextBox Then

If CType(c, TextBox).Text = "" Then

Exit Sub

End If

End If

Next

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:#x*************@TK2MSFTNGP11.phx.gbl...
B-Dog,
In addition to adding handlers for the Validating event that Terry (OHM) suggested.

I got the following tip from "Windows Forms Programming in C#" by Chris Sells, from Addison Wesley.

Within your "Accept" button click handler (the "save" button) process each control that CausesValidation to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesValidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.None
Exit For
End If
End If
Next

Note this version does not validate controls nested within other container controls, such as GroupBoxes...

The above code will cause the Validating event for each of your controls to
be raised, ensuring that all the controls get validated, before the dialog is closed or the data is saved...

Hope this helps
Jay

"B-Dog" <bd***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> I have a form that has about 10 text boxes on it, they all have to
be filled
> out before submitting is there a quick way to make sure that none

are null
> or do I have to call out each textbox? Say something like textbox1
through
> textbox10? Thanks
>
>



Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
5
by: Red | last post by:
Hi, I'm not very familiar with Javascript. I usually leave that kind of stuff up to Dreamweaver, but i'm starting to need a little more than it can offer. I have an asp page which creates a...
4
by: teknoshock | last post by:
I have created a page with multiple drop down boxes, all populated with the same options. My problem is, for 12 dropdown boxes and 40 choices per box, I end up with a massive file. Also, if I...
2
by: Neo Geshel | last post by:
Greetings, I have a form with a telephone field. It is very specific, as it has four text boxes - the country code, area code, prefix and suffix. I can validate each of them individually, but...
3
AMT India
by: AMT India | last post by:
I have an html form, that contains 100ds of text boxes. All have differnet ids. Can I validate all these text boxes using a single code? then how?
4
neo008
by: neo008 | last post by:
Hi all, Finally gave up and putting it here. I am new to visual basic stucked up with an error- Run time errors.'-2147217887 (8004021)': Multiple-step operation generated errors. check each...
4
by: Brybot | last post by:
I have a form that i've split up into multiple asp:panels, each panel has a number of validators which work correctly. At on the last panel, i want to commit the data collected to a database. I...
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
4
by: ghjk | last post by:
I want to validate my php site. I created javascript file for the validate functions. Eg: function validateFormOnSubmit(theForm) { var reason = ""; reason +=...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.