ASP.NET 遍历设置控件的只读属性(测试过)
2011-01-21 16:53
453 查看
for (int i = 0; i < Page.Controls.Count; i++)
{
//重点注意:System.Web.UI.Control ctr in Page.Controls[i].Controls,而不是Page.Controls
foreach (System.Web.UI.Control ctr in Page.Controls[i].Controls)
{
if (ctr is TextBox)
{
TextBox txtControl = (TextBox)ctr;
txtControl.ReadOnly = true;
txtControl.Enabled = false;
}
else if (ctr is RadioButton)
{
RadioButton btn = (RadioButton)ctr;
btn.Enabled = false;
}
else if (ctr is RadioButtonList)
{
RadioButtonList btn = (RadioButtonList)ctr;
btn.Enabled = false;
}
else if (ctr is CheckBox)
{
CheckBox cb = (CheckBox)ctr;
cb.Enabled = false;
}
else if (ctr is DropDownList)
{
DropDownList list = (DropDownList)ctr;
list.Enabled = false;
}
else if (ctr is HtmlTextArea)
{
HtmlTextArea cb = (HtmlTextArea)ctr;
cb.Attributes.Add("readonly", "");
cb.Disabled = true;
}
else if (ctr is HtmlSelect)
{
HtmlSelect rb = (HtmlSelect)ctr;
rb.Disabled = true;
}
else if (ctr is HtmlInputCheckBox)
{
HtmlInputCheckBox rb = (HtmlInputCheckBox)ctr;
rb.Disabled = true;
}
else if (ctr is HtmlInputRadioButton)
{
HtmlInputRadioButton rb = (HtmlInputRadioButton)ctr;
rb.Disabled = true;
}
else if (ctr is HtmlInputText)
{
HtmlInputControl input = (HtmlInputControl)ctr;
input.Attributes.Add("readonly", "readonly");
input.Disabled = true;
}
}
}
{
//重点注意:System.Web.UI.Control ctr in Page.Controls[i].Controls,而不是Page.Controls
foreach (System.Web.UI.Control ctr in Page.Controls[i].Controls)
{
if (ctr is TextBox)
{
TextBox txtControl = (TextBox)ctr;
txtControl.ReadOnly = true;
txtControl.Enabled = false;
}
else if (ctr is RadioButton)
{
RadioButton btn = (RadioButton)ctr;
btn.Enabled = false;
}
else if (ctr is RadioButtonList)
{
RadioButtonList btn = (RadioButtonList)ctr;
btn.Enabled = false;
}
else if (ctr is CheckBox)
{
CheckBox cb = (CheckBox)ctr;
cb.Enabled = false;
}
else if (ctr is DropDownList)
{
DropDownList list = (DropDownList)ctr;
list.Enabled = false;
}
else if (ctr is HtmlTextArea)
{
HtmlTextArea cb = (HtmlTextArea)ctr;
cb.Attributes.Add("readonly", "");
cb.Disabled = true;
}
else if (ctr is HtmlSelect)
{
HtmlSelect rb = (HtmlSelect)ctr;
rb.Disabled = true;
}
else if (ctr is HtmlInputCheckBox)
{
HtmlInputCheckBox rb = (HtmlInputCheckBox)ctr;
rb.Disabled = true;
}
else if (ctr is HtmlInputRadioButton)
{
HtmlInputRadioButton rb = (HtmlInputRadioButton)ctr;
rb.Disabled = true;
}
else if (ctr is HtmlInputText)
{
HtmlInputControl input = (HtmlInputControl)ctr;
input.Attributes.Add("readonly", "readonly");
input.Disabled = true;
}
}
}
相关文章推荐
- asp.net 遍历aspx页面中的TextBox控件,并设置属性为只读
- asp.net中遍历界面上所有控件进行属性设置
- ASP.NET中设置两级菜单联动用户控件的属性为外部使用
- asp.net在后台给前台的控件设置Style属性与坐标,后台设置CSS样式,后台获取前台控件坐标
- asp.net中的服务器端控件 textbox 设为只读属性后无法获取 javascript给其赋的值
- asp.net中的服务器端控件 textbox 设为只读属性后无法获取 javascript给其赋的值
- asp.net 的 textbox控件怎么设置readonly属性
- asp.net 遍历页面控件包含子控件,变为只读
- Asp.net 4000 _设置Button属性跳过控件验证
- asp.net中的服务器端控件 textbox 设为只读属性后无法获取 javascript给其赋的值
- Asp.net_设置Button属性跳过控件验证
- 如何:在 ASP.NET 网页中设置控件的 HTML 属性
- asp.net为前台Runat="server"控件设置样式和添加属性
- asp.net 在后台给前台的控件设置Style属性与坐标,后台设置CSS样式,后台获取前台控件坐标
- C# .NET 遍历一个Web页面中所有的TextBox控件 并设置读写属性
- asp.net中控件的enableviewstate属性 的设置
- asp.net中的服务器端控件 textbox 设为只读属性后无法获取JS给其赋的值解决办法
- asp.net在后台给前台的控件设置Style属性与坐标,后台设置CSS样式,后台获取前台控件坐标
- asp.net 在后台给前台的控件设置Style属性与坐标,后台设置CSS样式,后台获取前台控件坐标
- 在 ASP.NET 网页中设置控件的 HTML 属性