设置页面的所有控件为只读,不可用

ASP.NET后台控制前台页面中控件的属性

首先如果该控件是客户端控件先给其添加一属性runat="server",然后后台可以获取到该控件通过

this.txtName.Enabled = false;
this.txtName.ReadOnly = true;

这种方式进行一个一个控件进行控制
另一种方式可以通过循环对前台页面的所有控件进行控制

 foreach (Control ct in Page.Form.Controls)
                    {                        
                        if (ct is TextBox)
                        {
                            TextBox tb =(TextBox) ct;
                            tb.Enabled = false;
                        }
                        else if (ct is DropDownList)
                        {
                            
                            DropDownList ddl= (DropDownList)ct;
                            ddl.Enabled = false;  
                        }
                    }
原文地址:https://www.cnblogs.com/nyzhai/p/3054661.html