Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my Login form i have 2 textboxes (txtUsername and txtPassword) and 3 buttons- btnLogin, btnBack and btnCancel. I used errorProvider component to validate the 2 textboxes. Now the problem is, along with the Login button, the back and cancel button is also causing validation though i set the causes validation property of back and cancel button to 'false'. I want only the Login button to cause validation and not all the buttons in the form.
I used the following code to validate the textboxes and i am using visual studio 2010.
Private Sub txtUserName_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtUserName.Validating
        ErrorProvider1.SetError(txtUserName, "")
        With txtUserName
            If .Text = String.Empty Then
                BtnCancel_LoginForm.CausesValidation = False
                BtnBack_LoginForm.CausesValidation = False
                'cancel the event
                e.Cancel = True
                ErrorProvider1.SetError(txtUserName, "Required field")
                Label2.ForeColor = Color.Red
            Else
                Label2.ForeColor = Color.Maroon
            End If
        End With
    End Sub


Cant detect where and what is the mistake.. please somebody help....
Posted

1 solution

Set the 'CausesValidation' property of the back and cancel button in the designer itself or in form Init. Doing it in the validation event is too late.
 
Share this answer
 

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