Sé que esta es una publicación anterior, pero así es como acabo de resolver este problema. AS por el título "¿Cómo desactivo todos los controles en la página ASP.NET?" Usé Reflection para lograr esto; funcionará en todos los tipos de control que tengan una propiedad habilitada. Simplemente llame a DisableControls pasando el control padre (es decir, Formulario).
C#:
private void DisableControls(System.Web.UI.Control control)
{
foreach (System.Web.UI.Control c in control.Controls)
{
// Get the Enabled property by reflection.
Type type = c.GetType();
PropertyInfo prop = type.GetProperty("Enabled");
// Set it to False to disable the control.
if (prop != null)
{
prop.SetValue(c, false, null);
}
// Recurse into child controls.
if (c.Controls.Count > 0)
{
this.DisableControls(c);
}
}
}
VB:
Private Sub DisableControls(control As System.Web.UI.Control)
For Each c As System.Web.UI.Control In control.Controls
' Get the Enabled property by reflection.
Dim type As Type = c.GetType
Dim prop As PropertyInfo = type.GetProperty("Enabled")
' Set it to False to disable the control.
If Not prop Is Nothing Then
prop.SetValue(c, False, Nothing)
End If
' Recurse into child controls.
If c.Controls.Count > 0 Then
Me.DisableControls(c)
End If
Next
End Sub
¡Gracias! Quería desactivar todos los botones/cuadros de texto/cuadros combinados en un formulario a excepción de uno, y deshabilitar un panel deshabilita todos los controles para que no funcione. Usando su método, pude apagar solo los controles que quería, pero no los paneles. – ajs410