validation

plumage

Active member
Joined
Jul 12, 2004
Messages
38
Programming Experience
Beginner
all the validation below will work if i have any missing field.it will prompt me.
but the thing is after it prompt me the error, i enter the correct value,but how cum the validation txt would be still be there after the correct value had been enter?

how to make it disappeared?

pls help.
thank you.

'-- CHECK FOR VALID RECORD ---
Dim ValidRecord As Boolean = True

'-- Check for missing Name

If txtName.Text = "" Then

errorname.Text = "Missing Name"

ValidRecord =
False

End If

'-- Check for missing Address

If txtAddress.Text = "" Then

erroradd.Text = "Missing Address"

ValidRecord =
False

End If

'-- Check for valid Postal Code

If Not IsNumeric(txtPcode.Text) Then

errorPC.Text = "Invalid Postal Code format"

ValidRecord =
False

End If

'-- Check for missing Gender

If cboGender.Text = "" Then

errorGender.Text = "Missing Gender"

ValidRecord =
False

End If

'-- Check for missing contactno

If txtContactNo.Text = "" Then

errorContactNo.Text = "Missing Contact No"

Else

If Not IsNumeric(txtContactNo.Text) Then

errorContactNo.Text = "Invalid Contact No format"

ValidRecord =
False

End If

End If





'-- Check for missing DOB

If txtDOB.Text = "" Then

errorDOB.Text = "Missing DOB"

ValidRecord =
False



End If



'-- Check for missing IC

If txtIC.Text = "" Then

errorNRIC.Text = "Missing IC"

ValidRecord =
False

End If

 
The validation text is still there because you haven't removed it ;).

To remove the validation text, set the text property to an empty string.
example:
VB.NET:
errorname.Text = ""

I'm curious, is that a WebForm or winform? What are the controls that display the validation text (errorname, erroradd)?
 
'-- Check for missing IC

If txtIC.Text = "" Then

errorNRIC.Text = "Missing IC"

ValidRecord =
False

errorNRIC.text=""

EndIf

iszit sumting like this?
 
validation using msgbox

if i use msgbox to show the validation.
it work well when only if one or two field is empty, cos it will only prompt two msgbox after the submit button is press.

now, when i try to press submit with all field empty, alot of msgbox will prompt showing the validation..i think is very messy..iszit possible to also make juz a msgbox to be shown if all field are empty.
 
Instead of showing a messageBox for each error, you could use the ErrorProvider control. The ErrorProvider control is a property extender meaning it adds a property (the 'Error' property) to controls in the same container that can support said property. If you set the Error property for a control (a string message), an Icon is displayed near the control. When the user hovers the mouse over the Icon, the error is displayed as a toolTip. To remove the error, set the Error property to an empty string.

Here's some sample code for an errorProvider named ErrorProvider1 and a textBox that accepts a Date as the Text value:

VB.NET:
If Not IsDate(txtDate.Text) Then
    ErrorProvider1.SetError(Me.txtDate, "Please enter a valid date")
    bValidRecord = False
End If
 
Back
Top