This code will help you to loop through all control and child control in one page. To call the Following function you can use something like SetTextBoxBackColor(this.Page,Color.Yellow) in your code behind.
private void SetTextBoxBackColor(Control Page, Color clr)
{
foreach (Control ctrl in Page.Controls)
{
if (ctrl is TextBox)
{
((TextBox)(ctrl)).BackColor = clr;
}
else
{
if (ctrl.Controls.Count > 0)
{
SetTextBoxBackColor(ctrl, clr);
}
}
}
}
Reference:
http://steveorr.net/faq/controltreerecursion.aspx
Advertisement