473,729 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ 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 6693
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******** ********@TK2MSF TNGP09.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******** ********@tk2msf tngp13.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******** ********@TK2MSF TNGP09.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******** ******@tk2msftn gp13.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******** ********@tk2msf tngp13.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******** ********@TK2MSF TNGP09.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 CausesValidatio n to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesV alidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.No ne
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******** ********@TK2MSF TNGP09.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******** *****@TK2MSFTNG P11.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 CausesValidatio n to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesV alidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.No ne
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******** ********@TK2MSF TNGP09.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******** *****@TK2MSFTNG P11.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******** *****@TK2MSFTNG P11.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 CausesValidatio n to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesV alidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.No ne
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******** ********@TK2MSF TNGP09.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_Valida ting(ByVal sender As Object, _
ByVal e As System.Componen tModel.CancelEv entArgs) Handles
textBox1.Valida ting

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_Validat ing(ByVal sender As Object, _
ByVal e As System.Componen tModel.CancelEv entArgs) Handles
textBox1.Valida ting, TextBox2.Valida ting, TextBox3.Valida ting,
TextBox4.Valida ting

Dim txt As TextBox = DirectCast(send er, 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******** *****@TK2MSFTNG P11.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******** *****@TK2MSFTNG P11.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 CausesValidatio n to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesV alidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.No ne
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******** ********@TK2MSF TNGP09.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_Valida ting(ByVal sender As Object, ByVal e As
System.Componen tModel.CancelEv entArgs) Handles txtLName.Valida ting
Validate_LName( )
End Sub

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

Else
ErrorProvider1. SetError(txtLNa me, "")
' 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.EventArg s) Handles btnAccept.Click
Dim myNewhire As New ePCO.NewHireDet ails

' 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******** *****@TK2MSFTNG P11.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******** *****@TK2MSFTNG P11.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 CausesValidatio n to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesV alidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.No ne
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******** ********@TK2MSF TNGP09.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@DON T_SPAM_ME_hotma il.com> wrote in message
news:Od******** ******@TK2MSFTN GP12.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_Valida ting(ByVal sender As Object, ByVal e As
System.Componen tModel.CancelEv entArgs) Handles txtLName.Valida ting
Validate_LName( )
End Sub

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

Else
ErrorProvider1. SetError(txtLNa me, "")
' 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.EventArg s) Handles btnAccept.Click
Dim myNewhire As New ePCO.NewHireDet ails

' 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******** *****@TK2MSFTNG P11.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******** *****@TK2MSFTNG P11.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 CausesValidatio n to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesV alidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.No ne
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******** ********@TK2MSF TNGP09.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
8882
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
2605
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 form from a record set. Very simply it lists items that can be ordered by the customer. The customer simply enters the required qty for each item and hits submit:
4
1952
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 want to change or add options to a drop down box, I then have to copy that to the other 11 boxes. Would it be possible to define the options once, and then have all of the drop down boxes get their options from the single list? Here is my...
2
2393
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 I am stumped as to how to validate them as a group (as one final validation). I need to check to see if all (at one time) are filled or empty. The other individual validations handle cases where the text boxes are filled with letters or ...
3
1834
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
4032
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 status value. Error comes at ADODC.RECORDSET.UPDATE command.
4
2597
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 figured since all the panel data is still being sent through the postbacks, instead of using Sessions, or HttpContext, I could just take the values from the textboxes. This all works fine, except for security. I realized that I could inject...
1
4005
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. Depends on the pull down list selection, I use script.aculo.us to validate the user input before submit and pass the necessary data, such as contact type, contact information and ranking to a php program for updating. This form should allow multiple...
4
2335
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 += validateEmpty(theForm.from);
0
8763
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9284
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9202
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8151
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
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 we have to send another system
3
2165
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.