asp.net自动将页面中的所有空间置为不可用以及将所有文本框置空

/// <summary>
    /// 遍历页面上所有控件
    /// </summary>
    /// <param name="page">指定的Page</param>
    /// <param name="flag">false-不可用,true-可用</param>

    public void ControlReadOnly(System.Web.UI.Control page, bool flag)
    {
        int nPageControls = page.Controls.Count;
        for (int i = 0; i < nPageControls; i++)
        {
            foreach (System.Web.UI.Control control in page.Controls[i].Controls)
            {
                if (control is TextBox)
                    (control as TextBox).Enabled = flag;
                if (control is DropDownList)
                    (control as DropDownList).Enabled = flag;
            }
        }
    }
    /// <summary>
    /// 将文本框置空
    /// </summary>
    public void ClearAll(System.Web.UI.Control page)
    {
        int nPageControls = page.Controls.Count;
        for (int i = 0; i < nPageControls; i++)
        {
            foreach (System.Web.UI.Control control in page.Controls[i].Controls)
            {
                if (control is TextBox)
                    (control as TextBox).Text = "";
                if (control is Label)
                    (control as Label).Text = "";
            }
        }
    }

 

posted @ 2016-11-25 15:06  雅比斯  阅读(320)  评论(0编辑  收藏  举报