×

Welcome to TagMyCode

Please login or create account to add a snippet.
1
0
 
0
Language: C#
Posted by: petecocoon
Added: May 24, 2012 3:05 PM
Modified: Jun 1, 2012 7:46 AM
Views: 69
  1. public Control FindControlRecursiveByTag(Control container, String tag)
  2.         {
  3.             if (container.Tag != null && container.Tag.ToString() == tag)
  4.                 return container;
  5.  
  6.             foreach (Control ctrl in container.Controls)
  7.             {
  8.                 Control foundCtrl = FindControlRecursiveByTag(ctrl, tag);
  9.                 if (foundCtrl != null)
  10.                     return foundCtrl;
  11.             }
  12.             return null;
  13.         }