Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: COLLECTION


Message #1 by "Claudio Pallone" <claudio.pallone@k...> on Tue, 18 Mar 2003 15:30:57
Claudio,

Any object with controls encapsulated in it will have a controls collection.
Using the "Dim" keyword to create a controls collection will create an empty
one.  There will be no controls on it to iterate through. If you are using a
Button click event to handle this you are going to want to specifically
address the form when using the Controls property.  You can use
myForm.Controls.Count where "myForm" is the name of the form containing the
controls, instead of simply Controls.Count.  You can also use
"Me.Controls.Count" if you are referring to the current class/form. You may
wish to run this in debug and use the immediate window to query the value of
each of these expressions.  You may get your answer there.

Regards
----- Original Message -----
From: "Claudio Pallone" <claudio.pallone@k...>
To: "ASPX_Professional" <aspx_professional@p...>
Sent: Tuesday, March 18, 2003 3:30 PM
Subject: [aspx_professional] COLLECTION


> Hi,
>
> I am trying to loop through a webform to get the id of all the controls on
> the page (listbox, ddl, textbox, etc...)
>
> I have posted below my attempts to do that but to no avail.
>
> Since I can not figure out how to do that, I was wondering if someone
> could help me.
>
> Cheers,
>
> Claudio
>
> Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnGet.Click
>         'Dim lc As Control
>         'Label2.Text = lc.ID
>         'Label2.Text = Controls.Count
>         'Dim i As Integer
>         'For i = 0 To Controls.Count - 1
>         'Label2.Text = Controls.GetType.ToString
>
>         'Next
>         Dim myControlsCollection As ControlCollection
>         myControlsCollection = Controls
>         'myControlsCollection.()
>         Dim li As ListControl
>         'Dim li As Controls
>         For Each li In myControlsCollection
>             Label2.Text = li.ID.ToString
>         Next
>
>     End Sub
>
>


  Return to Index