设置页面所有控件

private void InItControl( ControlCollection connection)
    {
        foreach (System.Web.UI.Control ctrl in connection)
        {
            if (ctrl.HasControls())
            {
                InItControl(ctrl.Controls);
            }
            else
            {
                if (ctrl is System.Web.UI.WebControls.TextBox)
                {
                    ((TextBox)ctrl).ReadOnly = true;
                }
                if (ctrl is System.Web.UI.WebControls.DropDownList)
                {
                    ((DropDownList)ctrl).Enabled = false;
                }
                if (ctrl is System.Web.UI.WebControls.RadioButtonList)
                {
                    ((RadioButtonList)ctrl).Enabled = false;
                }
                if (ctrl is System.Web.UI.WebControls.CheckBox)
                {
                    ((CheckBox)ctrl).Enabled = false;
                }
                if (ctrl is System.Web.UI.WebControls.Button)
                {
                    ((Button)ctrl).Enabled = false;
                }
                if (ctrl is System.Web.UI.WebControls.LinkButton)
                {
                    ((LinkButton)ctrl).Enabled = false;
                }
            }
        }
    }






在我的页面上目前只有这些控件   有其他需要设置的   按照方法向上加就是
在调用的时候写InItControl(Page.Controls);
原文地址:https://www.cnblogs.com/88223100/p/1230093.html