Link to home
Start Free TrialLog in
Avatar of miyahira
miyahiraFlag for Peru

asked on

Get all controls of others web pages

I need to list all controls of all aspx web pages in a project.
I have the code for getting all control of current aspx page (webform1.aspx):

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then

            ListControlCollections()

        End If
    End Sub

    Private Sub ListControlCollections()
        Dim controlList As New ArrayList()
        AddControls(Page.Controls, controlList)

        For Each str As String In controlList

            Response.Write(str & "<br/>")


        Next
        Response.Write("Total Controls:" + controlList.Count.ToString)
    End Sub

    Private Sub AddControls(ByVal page As ControlCollection, ByVal controlList As ArrayList)
        For Each c As Control In page
            If c.ID IsNot Nothing Then
                If c.ID <> "0" Then
                    controlList.Add(c.ID)
                End If

            End If

            If c.HasControls() Then
                AddControls(c.Controls, controlList)
            End If
        Next
    End Sub

Open in new window


Problem is when I try to call the controls of other webpages (webform2.aspx, webform3.aspx, etc). Example:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim Page As New WebForm2()
            ListControlCollections(Page)

           'Also I try this code, but get nothing:
            Dim x As New WebForm2()
            For Each ctrl As Control In x.Controls
                Response.Write(ctrl.ID & "<br/>")

            Next

        End If
    End Sub

Private Sub ListControlCollections(ByVal Page As Page)
        Dim controlList As New ArrayList()
        AddControls(Page.Controls, controlList)

        For Each str As String In controlList
            Response.Write(str & "<br/>")
        Next
        Response.Write("Total Controls:" + controlList.Count.ToString)
    End Sub

Open in new window

I get none controls of webform2.aspx

Is it possible to get all controls of other web pages?
ASKER CERTIFIED SOLUTION
Avatar of Roopesh Reddy
Roopesh Reddy
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial