VB.net从后面的代码中禁用CompareValidator

时间:2012-09-13 09:12:31

标签: asp.net vb.net requiredfieldvalidator

是否可以从VB.net中的代码中禁用CompareValidator / RequiredFieldValidator

我有3个字段(下拉列表和两个日期选择器),从下拉列表中选择一个月后我想禁用datepicker输入上的验证/必需

任何建议都非常感谢!

请注意已经尝试过这个,但它不起作用:

Protected Sub DashbodropardMonthsDropDown_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DashbodropardMonthsDropDown.SelectedIndexChanged
        ' If Month is selected from DD menu
        Dim MonthDD As Integer = DashbodropardMonthsDropDown.SelectedValue

        ' If nothing selected or selected "--select" with value 0
        If MonthDD = 0 Then

            'Validate DatePicker
            CompareValidatorT1.Enabled = True
            RequiredFieldValidator2.Enabled = True
            RequiredFieldValidator1.Enabled = True

        Else

            'Do Not Validate DatePicker
            CompareValidatorT1.Enabled = False
            RequiredFieldValidator2.Enabled = False
            RequiredFieldValidator1.Enabled = False


        End If

    End Sub

1 个答案:

答案 0 :(得分:1)

您可以通过执行此类操作

来启用或禁用code behind的验证程序
CompValidator.Enabled=false

修改AutoPostBack=true帮助设置DropDownList