0

Is there some generic method to find all server controls of a page in asp.net webforms?

I'm using this method to do that, but it is not finding the controls inside an asp:Repeater:

private void GetControlList<T>(ControlCollection controlCollection, List<T> resultCollection) where T : Control
{
     foreach (Control control in controlCollection)
     {
         if (control is T)
             resultCollection.Add((T)control);

         if (control.HasControls())
             GetControlList(control.Controls, resultCollection);
     }
}

Thanks!

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Cristiano Sarmento
  • 633
  • 2
  • 9
  • 19
  • 4
    Has `DataBind()` been called on the repeater? If not, the repeater's `Controls` collection won't be populated. – Michael Liu Jul 09 '14 at 14:03
  • 2
    Your method is correct - I use a similar one myself a lot. Michael Liu is correct - the repeater is probably not data bound yet. – cbp Jul 09 '14 at 14:14
  • It was the problem. My repeater was filled after the find controns methos execution. Thanks to all! – Cristiano Sarmento Jul 09 '14 at 14:22

0 Answers0