我正在尝试检查位于母版页内的网络表单 (aspx) 页面上的所有复选框,具体取决于复选框的 ID。复选框是动态创建的,所以我只知道找到它的前缀。所以,我需要通过以某种方式迭代页面上的控件来找到这些复选框。
以下是应进行检查的代码:
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim oCheckbox As System.Web.UI.WebControls.CheckBox = Nothing
Dim oControl As Control = Nothing
For Each oControl In Me.Controls
If oControl IsNot Nothing Then
If TypeOf oControl Is System.Web.UI.WebControls.CheckBox Then
oCheckbox = oControl
If oCheckbox.Text.StartsWith("ClientCheckBox_") Then
oCheckbox.Checked = True
End If
End If
End If
Next
End Sub