How do I disable all controls in ASP.NET page?

后端 未结 9 1666
旧时难觅i
旧时难觅i 2020-12-14 08:17

I have multiple dropdownlist in a page and would like to disable all if user selects a checkbox which reads disable all. So far I have this code and it is not working. Any s

9条回答
  •  无人及你
    2020-12-14 09:08

    Here's a VB.NET version which also takes an optional parameter so it can be used for enabling the controls as well.

    Private Sub SetControls(ByVal parentControl As Control, Optional ByVal enable As Boolean = False)

        For Each c As Control In parentControl.Controls
            If TypeOf (c) Is CheckBox Then
                CType(c, CheckBox).Enabled = enable
            ElseIf TypeOf (c) Is RadioButtonList Then
                CType(c, RadioButtonList).Enabled = enable
            End If
            SetControls(c)
        Next
    
    End Sub
    

提交回复
热议问题