rwallacej
asked on
Iterate through all custom controls
Hi
I have a page with custom controls on it. The custom control is called UserControls_TestControlWi thProperty . There may be one, more or many of the UserControls_TestControlWi thProperty on the page.
I want to iterate through all the controls on page, and if the control is of type UserControls_TestControlWi thProperty 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_TestControlWi thProperty objects so I can cast and modify them.
Thank-you.
I have a page with custom controls on it. The custom control is called UserControls_TestControlWi
I want to iterate through all the controls on page, and if the control is of type UserControls_TestControlWi
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
Are you using a masterpage?
ASKER
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)
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)
ASKER
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank-you very much, this works