Control Finder in ASP.Net

Posted by Ndebata under ASP.NET category on | Points: 40 | Views : 3978
Some days back I saw in a forum, the user wants to find TextBox or Label in a wizard control while using some custom template.
This code segment will help for finding out the controls in the control tree.
I am not doing anything, just searching the controls in a recursive way, if got that control returns it.

public Control FindMyControl(Control ctrl, string NameofControlToFind)
Control found = ctrl.FindControl(NameofControlToFind);
if (found != null)
return found;
foreach (Control item in ctrl.Controls)
return FindMyControl(item, NameofControlToFind);
return null;


Comments or Responses

Posted by: CS1401 on: 7/8/2011 Level:Starter | Status: [Member] | Points: 10
wow really great article.!! U really brilliant.!!

Login to post response