0

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

我有 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
4

1 回答 1

1

code behind您可以通过执行以下操作来启用或禁用您的验证器

CompValidator.Enabled=false

编辑: 设置AutoPostBack=true帮助DropDownList

于 2012-09-13T09:14:48.650 回答