Geekpedia Programming Tutorials






Find Controls In MasterPages Recursively

A useful piece of code that enhances the search for the control with the specified name under the passed parent control.

On Saturday, October 4th 2008 at 12:51 PM
By Andrew Pociu (View Profile)
****-   (Rated 4 with 1 votes)
Contextual Ads
More C# Resources
Advertisement
  1. public static Control FindControlR(Control CtrlRoot, string CtrlID)
  2. {
  3.         if (Root.ID == CtrlID) // If the name of the control is the same as the name we were looking for
  4.         {
  5.                 return Root; // We've found the control
  6.         }
  7.  
  8.         foreach (Control Ctrl in Root.Controls) // Loop through all the controls of the current element
  9.         {
  10.                 Control FoundCtrl = FindControlR(CtrlRoot, CtrlID); // Continue looking
  11.                 if (FoundCtrl != null)
  12.                 {
  13.                         return FoundCtrl;
  14.                 }
  15.         }
  16.         return null;
  17. }
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this code snippet
Comment Current Comments
There are no comments.

Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs C# Job Search
My skills include:

Enter a City:

Select a State:


Advanced Search >>
Latest Tech Bargains

Advertisement

Free Magazine Subscriptions

Today's Pictures

Today's Video

Other Resources

Latest Download

Latest Icons