Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I have a form and I want to ensure that none of the input fields should be left blank and the txtUPrice should hold only numeric values.

The below is the code that I devised.

Initially when I checked for focus issues (Initial IF structure) it went fine. But when I implemented numeric checking (Second IF structure), the system is not responding. However I am able to type and can move to the next text box. If I try ignoring input in any of the box, it is not showing the error provider and I am stuck in the same box (because of focus method). What went wrong in my code? Is there any conflict between first IF and second IF structures?

Please help.

VB
Private Sub ValidateFields(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtProdID.Leave, txtProdDesc.Leave, txtUOM.Leave, txtUPrice.Leave, txtVendor.Leave
        Dim x As TextBox
        x = sender
        If x.Text = "" Then
            x.Focus()
            ErrPvdr.SetError(x, "Cannot be a blank input")
        Else
            ErrPvdr.Clear()
        End If
        If x.Name = "txtuprice" And (Not IsNumeric(x.Text)) Then
            x.Focus()
            ErrPvdr.SetError(x, "Cannot be a non numeric value")
        Else
            ErrPvdr.Clear()
        End If
    End Sub
Posted
Updated 5-Jan-12 23:59pm
v3
Comments
Sergey Alexandrovich Kryukov 6-Jan-12 5:59am    
Where is "delegation"?
--SA
Nara Har 6-Jan-12 6:03am    
The delegation is internally handled by .NET.

1 solution

Yes, your second "if" is messing things up.
Try
VB
If x.Text = "" Then
    x.Focus()
    ErrPvdr.SetError(x, "Cannot be a blank input")
ElseIf x.Name = "txtUprice" And (Not IsNumeric(x.Text)) Then
    x.Focus()
    ErrPvdr.SetError(x, "Cannot be a non numeric value")
Else
    ErrPvdr.Clear()
End If


Cheers
 
Share this answer
 
Comments
Nara Har 6-Jan-12 6:17am    
Thank you this worked
Estys 6-Jan-12 6:22am    
Thanks for your feedback, it's always nice to know whether something worked or not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900