Thursday, February 7, 2013

Finding a Control on a Page

Control c = FindControlRecursive(Page, "ControlId");if (c != null){
  ...//Process control
}


private Control FindControlRecursive(Control root, string id) {
  if(root.ID==id)   {
    return root;  }

  foreach(Control c in root.Controls)
  {
    Control
t = FindControlRecursive(c, id);
    if
(t != null)     {
      return
t;    } 
  }
 
  return
null;}

No comments: