开发者

Enumerate all controls in the form

开发者 https://www.devze.com 2023-01-27 23:02 出处:网络
private void EnableControls(bool enable) { foreach (TextBox t in Page.Form.Controls.OfType<TextBox>())
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

精彩评论

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