本文介绍了导致错误提供程序的验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的登录表单中,我有2个文本框(txtUsername和txtPassword)和3个按钮-btnLogin,btnBack和btnCancel.我使用errorProvider组件来验证2个文本框.现在的问题是,尽管我将返回"和取消"按钮的causes验证属性设置为"false",但与登录"按钮一起,返回"和取消"按钮也引起了验证.我只希望登录"按钮引起验证,而不希望表单中的所有按钮.
我使用以下代码来验证文本框,并且我正在使用Visual Studio2010.

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....

推荐答案


这篇关于导致错误提供程序的验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:09