Skip to content

Instantly share code, notes, and snippets.

Created August 31, 2012 13:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
using System.Collections.Generic;
// accesses a control by ID (i.e. a checkbox/button/textbox etc)
private static Control FindControlIterative(Control root, string id)
Control ctl = root;
LinkedList<Control> ctls = new LinkedList<Control>();
while (ctl != null)
if (ctl.ID == id)
return ctl;
foreach (Control child in ctl.Controls)
if (child.ID == id)
return child;
if (child.HasControls())
ctl = ctls.First.Value;
return null;
// To call the method, use something like:
public MainMethod()
// get a textbox that has the ID "address"
TextBox txt = FindControlIterative(control, "address") as TextBox;
// change the text of that textbox
txt.Text = "some text";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment