一切为了DotNet

念天地之悠悠,独怆然而涕下

 

关于vb.net如何获取页面上所有控件

今天碰到一个问题,需要从页面上获取所有的控件,不知道怎么回事,页面上总会出现一些莫名其妙的控件,可能是VS自动生成的吧?
 1Private 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

posted on 2006-07-27 20:22  一切为了DotNet  阅读(1697)  评论(1编辑  收藏  举报

导航