CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

FindControlUsingStack

152 Views
Copy Code Show/Hide Line Numbers
public static Control FindControlUsingStack(Control root, string id)
{
   // Seed it.
   Stack<Control> stack = new Stack<Control>();
   stack.Push(root);
 
   while(stack.Count > 0)
   {
      Control current = stack.Pop();
      if (current.ID == id)
         return current;
 
      foreach (Control control in current.Controls)
      {
         stack.Push(control);
      }
   }
   return null;
}
by Arjan
  June 24, 2010 @ 4:06am
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate