Iterate through all custom controls

Hi

I have a page with custom controls on it. The custom control is called UserControls_TestControlWithProperty. There may be one, more or many of the UserControls_TestControlWithProperty on the page.
I want to iterate through all the controls on page, and if the control is of type UserControls_TestControlWithProperty do something with it. Unfortunately the code I have tried /changed isn't finding the controls of this type. See some code below and output from the code, hopefully this will assist in finding the UserControls_TestControlWithProperty objects so I can cast and modify them.

Thank-you.
Dim r As String = "DETAILS OF ALL TAG OBJECTS"
            For Each c As Control In Me.Controls
                Response.Write(c.ToString & "<p>")
                Response.Write(c.ClientID & "<p>")
 
                'If TypeOf (c) Is UserControls_TestControlWithProperty Then
                'r = r & vbCrLf & DirectCast(c, UserControls_TestControlWithProperty).TS.ToString
                'End If
 
 
                If TypeOf (c) Is System.Web.UI.HtmlControls.HtmlForm Then
                    Dim cd As HtmlForm = DirectCast(c, HtmlForm)
                    For Each d As Control In cd.Controls
                        Response.Write("--> " & d.ToString & ".....     CLIENTID: " & d.ClientID & "<p>")
                        Response.Write("----> TYPE: " & d.GetType.ToString & "<p>")
 
                        If TypeOf d Is LiteralControl Then
                            Dim dc As LiteralControl = DirectCast(d, LiteralControl)
 
                            For Each dcc As Control In dc.Controls
                                Response.Write("---> --> -->" & dcc.ToString & ".     " & dcc.ClientID & "<p>")
                            Next
                        ElseIf TypeOf (c) Is UserControls_TestControlWithProperty Then
                            Response.Write("<h1>UserControls_TestControlWithProperty </h1>")
                            'never get in here
                            Response.Write("<p><b>" & DirectCast(c, UserControls_TestControlWithProperty).TS.ToString & "</b><p>")
                        ElseIf TypeOf (c) Is ASP.tests_usercontrols_testcontrolwithproperty_ascx Then
                            'never get in here
                            Response.Write("this is it here.......................<p>")
                        End If
 
 
 
                    Next
                End If
            Next
 
 
 
OUTPUTS
System.Web.UI.LiteralControl
ctl02
 
System.Web.UI.HtmlControls.HtmlHead
 
ctl00
 
System.Web.UI.LiteralControl
 
ctl03
 
System.Web.UI.HtmlControls.HtmlForm
 
form1
 
--> System.Web.UI.LiteralControl..... CLIENTID: ctl04
 
----> TYPE: System.Web.UI.LiteralControl
 
--> ASP.tests_usercontrols_testcontrolwithproperty_ascx..... CLIENTID: TestControlWithProperty1
 
----> TYPE: ASP.tests_usercontrols_testcontrolwithproperty_ascx
 
--> System.Web.UI.LiteralControl..... CLIENTID: ctl05
 
----> TYPE: System.Web.UI.LiteralControl
 
--> System.Web.UI.WebControls.Button..... CLIENTID: Button1
 
----> TYPE: System.Web.UI.WebControls.Button
 
--> System.Web.UI.LiteralControl..... CLIENTID: ctl06
 
----> TYPE: System.Web.UI.LiteralControl
 
--> System.Web.UI.WebControls.TextBox..... CLIENTID: TextBox1
 
----> TYPE: System.Web.UI.WebControls.TextBox
 
--> System.Web.UI.LiteralControl..... CLIENTID: ctl07
 
----> TYPE: System.Web.UI.LiteralControl
 
System.Web.UI.LiteralControl
 
ctl08

Open in new window

rwallacejAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Praveen VenuTechnical Project ManagerCommented:
Are you using a masterpage?
rwallacejAuthor Commented:
hi,
no I am not using master page, this is just a plain .ASPX page with controls on it (I will use a master page eventually though)
rwallacejAuthor Commented:
here is the contents of it
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TestingTagControl.aspx.vb" Inherits="Tests_TestingTagControl" %>
 
<%@ Register src="UserControls/TestControlWithProperty.ascx" tagname="TestControlWithProperty" tagprefix="uc1" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <uc1:TestControlWithProperty ID="TestControlWithProperty1" runat="server" /><p></p>
<%--        <uc1:TestControlWithProperty ID="TestControlWithProperty2" runat="server" /><p></p>
        <uc1:TestControlWithProperty ID="TestControlWithProperty3" runat="server" /><p>
--%>            <asp:Button ID="Button1" runat="server" Text="Button" />
<%--        </p>
--%>
    </div>
    <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Height="248px" 
        Width="1065px"></asp:TextBox>
    </form>
</body>
</html>

Open in new window

Praveen VenuTechnical Project ManagerCommented:
why can not put a panel and put all your controls inside the panel and then loop

Panel1.Controls

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rwallacejAuthor Commented:
thank-you very much, this works
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.