遍历TEXTBOX

来源:互联网 发布:单片机 interrupt用法 编辑:程序博客网 时间:2024/04/29 23:24

asp.net 不能像window那样直接遍历this.Controls就可以了,因为:

this.Controls只是包含了Page根一级的control,这样次级的control就都没有遍历
TextBox一般会放在form里面,遍历this.Controls只会访问form control,而不会访问form的子Contorl
下面使用递归对页面control树进行完全遍历

    private void ResetTextBox(ControlCollection cc)
    {
        foreach (Control ctr in cc)
        {
            if (ctr.HasControls())
            {
                ResetTextBox(ctr.Controls);
            }
            if (ctr is TextBox)
            {
                ((TextBox)ctr).Text = string.Empty;
            }
        }
    }

调用

ResetTextBox(this.Controls);
 

原创粉丝点击