关于vb.net如何获取页面上所有控件
今天碰到一个问题,需要从页面上获取所有的控件,不知道怎么回事,页面上总会出现一些莫名其妙的控件,可能是VS自动生成的吧?
1
Private Function GetAllControls(ByVal frm As Control) As Integer
2
Dim iCount As Integer = frm.Controls.Count
3
Dim i As Integer
4
For i = 0 To iCount - 1
5
For Each con As Control In frm.Controls(i).Controls
6
If Not con.HasControls() Then
7
If TypeOf con Is WebControls.RequiredFieldValidator Then
8
CType(con, RequiredFieldValidator).EnableClientScript = False
9
ElseIf TypeOf con Is WebControls.CompareValidator Then
10
CType(con, CompareValidator).EnableClientScript = False
11
End If
12
End If
13
Next
14
Next
15
End Function
Private Function GetAllControls(ByVal frm As Control) As Integer2
Dim iCount As Integer = frm.Controls.Count3
Dim i As Integer4
For i = 0 To iCount - 15
For Each con As Control In frm.Controls(i).Controls6
If Not con.HasControls() Then7
If TypeOf con Is WebControls.RequiredFieldValidator Then8
CType(con, RequiredFieldValidator).EnableClientScript = False9
ElseIf TypeOf con Is WebControls.CompareValidator Then10
CType(con, CompareValidator).EnableClientScript = False11
End If12
End If13
Next14
Next15
End Functionposted on 2006-07-27 20:22 一切为了DotNet 阅读(1737) 评论(1) 收藏 举报

浙公网安备 33010602011771号