2
private void EnableControls(bool enable)
        {
            foreach (TextBox t in Page.Form.Controls.OfType<TextBox>())
            {
                t.ReadOnly = !enable;
            }
            chkSameAsCurrent.Enabled = enable;
        }

The above code runs fine in a simple page not having any master page, but if I run it in a ContentPage I can not enumerate the TextBoxes and not even any control in the form.

teenup
  • 7,459
  • 13
  • 63
  • 122

2 Answers2

2

Try this. I think this should work.

 private void RecursiveLoopThroughControls(Control root)
 {
      foreach (Control control in root.Controls)
      {
          RecursiveLoopThroughControls(control);
          //process the control.
      }
 }

Call the method using

 RecursiveLoopThroughControls(Page)
dhinesh
  • 4,676
  • 2
  • 26
  • 44
0

You definitely should do this through recursion. Try this article. If you want to enumerate Master Page controls - follow them in Page.Master

Community
  • 1
  • 1
Genius
  • 1,784
  • 14
  • 12