I developed a web control panel that has a structure of controls embedded inside the controls. In many scenarios, I have a control identifier and should work on the actual control. Thus, I use the utility method - a recursive implementation of FindControl, which searches for the page (or any other provided object, but I always use the page) for the identifier of the control.
/// <summary> /// Page.FindControl is not recursive by default. /// </summary> /// <param name="root"> Page </param> /// <param name="id"> ID of control looking for. </param> /// <returns> The control if found, else null. </returns> public static Control FindControlRecursive(Control root, string id) { if (int.Equals(root.ID, id)) { return root; } foreach (Control control in root.Controls) { Control foundControl = FindControlRecursive(control, id); if (!object.Equals(foundControl,null)) { return foundControl; } } return null; }
This feature has the ability to become quite slow. I understand how slow I entered log4net into it. Now I'm trying to move away from him where I can, but I'm not sure what other options I have, if any.
For example, a user drags a control onto my web page. The event handler is as follows:
protected void RadListBox_Dropped(object sender, RadListBoxDroppedEventArgs e) {
There is no guarantee that this control will be a direct child of the page, and I cannot (as far as I know!) Have the ability to determine where in my controls this identifier can be, except by searching from page down.
The only thing I can think of is to save the lookup table of each object on the page, but this seems like a wrong idea.
Has anyone else experienced this issue?
source share