Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Find a control by ID
Message
From
02/05/2012 14:57:42
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Find a control by ID
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01543059
Message ID:
01543059
Views:
71
I need to find a control in a WebForm by ID. I have the code to scan the page by hierarchy. However, this only applies for as long as each control have the runat server. If I have a Body tag with runat server, this is good. Then, it scans for child controls for all runat controls. But, if I have a table defined and in one of the cell I have the runat server, how can I find this control?

This is the recursive method:
        ' See if a control ID exists
        ' expO1 Control
        ' expC1 ID
        Public Function IsPageControlExistByID(ByVal toControl As Object, ByVal tcID As String) As Boolean
            Dim loControl As System.Web.UI.Control = New System.Web.UI.Control

            ' For each control
            For Each loControl In toControl.Controls

                ' If this is the ID
                If loControl.ID = tcID Then
                    Return True
                End If

                ' If we have child controls
                If loControl.HasControls Then

                    ' If the control exists
                    If IsPageControlExist(loControl, tcID) Then
                        Return True
                    End If

                End If

            Next

            Return False
        End Function
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform