Get all controls of others web pages

miyahira
miyahira used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Analyst
Top Expert 2012
Commented:
Hi,

No. You can get the current rendered Page controls only!

You can check the JavaScript solutions here - http://forums.asp.net/t/1908996.aspx?Get+all+controls+from+another+page

but i don't think it's feasible for you!

Hope it helps u...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial