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
精彩评论