要禁用ASP.NET页面中的所有控件,可以使用以下方法:
protected void DisableAllControls(Control parent)
{
foreach (Control ctrl in parent.Controls)
{
if (ctrl is Panel || ctrl is PlaceHolder)
{
DisableAllControls(ctrl);
}
else
{
ctrl.Enabled = false;
}
}
}
然后在页面的生命周期中调用该方法:
protected void Page_Load(object sender, EventArgs e)
{
DisableAllControls(this);
}
function disableAllControls() {
var controls = document.getElementsByTagName("input");
for (var i = 0; i< controls.length; i++) {
controls[i].disabled = true;
}
var controls = document.getElementsByTagName("select");
for (var i = 0; i< controls.length; i++) {
controls[i].disabled = true;
}
var controls = document.getElementsByTagName("textarea");
for (var i = 0; i< controls.length; i++) {
controls[i].disabled = true;
}
var controls = document.getElementsByTagName("button");
for (var i = 0; i< controls.length; i++) {
controls[i].disabled = true;
}
}
然后在页面加载时调用该方法:
<body onload="disableAllControls()">
这样就可以禁用ASP.NET页面中的所有控件了。
领取专属 10元无门槛券
手把手带您无忧上云