I.T. Discussion Community!
-Collapse +Expand
C#
Search C# Group:

Advanced
-Collapse +Expand C# To/From
To/FromCODEGuides
-Collapse +Expand C# Study Test
PRESTWOODCERTIFIED
-Collapse +Expand C# Store
PRESTWOODSTORE

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingC#WebForms Cod...   Print This     
  From the August 2015 Issue of Prestwood eMag
 
C# WebForms Coding Tasks:
Get all components in an ASPX page recursively
 
Posted 12 years ago on 3/8/2008 and updated 2/24/2009
C# Code Snippet:
 A flashcard from our C# Flashcards Library
 A code snippet from our C# Code Snippets Page

KB100929

Retrieves an array of all the components of any given type within a starter control (such as a page, table, panel, etc.)  This routine is recursive and will keep iterating down until all the embedded components are found.

This C# code can be invoked to produce an array as  follows:

CheckBox[] myCheckboxes = GetAllCheckboxes(Table1); 
Syntax Example:
public CheckBox[] GetAllCheckboxes(Control myControl)
{
  ArrayList myCheckboxes = new ArrayList();
 
  foreach (Control thisControl in myControl.Controls)
  {
    if (thisControl is CheckBox)
    {
      myCheckboxes.Add(thisControl);
    }
 
    if (thisControl.HasControls())
    {
      myCheckboxes.AddRange(GetAllCheckboxes(thisControl));
    }            
  }
 
  CheckBox[] result = (CheckBox[])myCheckboxes.ToArray(typeof(CheckBox));
  return result;
}

Comments

1 Comments.
Share a thought or comment...
Comment 1 of 3

Thank you for posting this. Just what I needed.

Posted 12 years ago

Comment 2 of 3

Gracias. Muy buen aporte. Saludos desde Salta Capital - Argentina

---
Salta Capital
Posted 6 years ago

Comment 3 of 3

This is my first time visit here. I read your post and found it quite interesting and Likewise fantastic blog here among many of the costly info you acquire.  :)

Posted 22 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P115A1
Enter key:
Code Contributed By Bryan Valencia:

Bryan Valencia is the author of millions of lines of code and writes for PrestwoodBoards and Visual Studio Journey on-line magazines.

Visit Profile

 KB Article #100929 Counter
10736
Since 4/2/2008

Follow PrestwoodBoards on: 


©1995-2020 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech