Hi Sacha,
I suspect you're not looking in the right collection for the controls that
you are after. It helps to put tracing on to see the hierarchy of controls
on the ASP.NET page. As you'll see, the Form controls are inside containers.
Also, if you are using other containers you might have to drill down
further.
I've put some code below that shows how you might get the total count of
controls and the DDLs. (Watch for bad line wrapping.)
Let us know if this helps?
Ken
Microsoft MVP [ASP.NET]
Toronto
Public Class hw_edit
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents DropDownList1 As
System.Web.UI.WebControls.DropDownList
Protected WithEvents DropDownList2 As
System.Web.UI.WebControls.DropDownList
Protected WithEvents DropDownList3 As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Public intControlCount As Integer
Public intDDLCount As Integer
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Page_PreRender(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.PreRender
Dim cntrl As Control
For Each cntrl In Page.Controls(1).Controls
If TypeOf (cntrl) Is System.Web.UI.WebControls.DropDownList Then
intDDLCount = intDDLCount + 1
End If
Next
Label1.Text = "Number of DDLs: " & intDDLCount.ToString & _
"<br>Number of Controls: " &
Page.Controls(1).Controls.Count.ToString
End Sub
End Class
<%@ Page Language="vb" trace="true" AutoEventWireup="false"
Codebehind="cntrlscount.aspx.vb" Inherits="p4320work.hw_edit"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>cntrlscount</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<p>
<asp:dropdownlist id="DropDownList1"
runat="server"></asp:dropdownlist>
<asp:dropdownlist id="DropDownList2"
runat="server"></asp:dropdownlist>
<asp:dropdownlist id="DropDownList3"
runat="server"></asp:dropdownlist></p>
<p>
<asp:label id="Label1"