Recursive Method to find control in complex page
Today I'm going to show you a simple method to find a control (Textbox, Dropdown, Label) in a complex Page where default findControl method is not useful. Using this method you can identify the control easily and it's recursive method so the LOC is few. enjoy it.
hmmm That's all.simple huh. happy coding and have a nice day.
/// <summary>
/// Find a control when Root control is known
/// </summary>
/// <param name="rootControl">Instance of the Root control</param>
/// <param name="controlToFind">Name of the control to find</param>
/// <returns></returns>
private Control FindControl(Control rootControl, string controlToFind)
{
return rootControl.ID == controlToFind ? rootControl :
(from Control control in rootControl.Controls select this.FindControl(control, controlToFind)).FirstOrDefault(t => t != null);
}
hmmm That's all.simple huh. happy coding and have a nice day.
Comments
Post a Comment