开发者

Enumerate all controls in the form

private void EnableControls(bool enable)
        {
            foreach (TextBox t in Page.Form.Controls.OfType<TextBox>())
            {
                开发者_Go百科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.


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜