You can just use "not
IsDisable
" versus the
IF
...
ELSE
block. Additionally, the recursive call to
ControlStatus
should be done all the time so that the parent control is enabled/disabled along with the children.
public void ControlStatus(Control control, bool isDisable)
{
foreach (Control c in control.Controls)
try
{
if (c is WebControl)
((WebControl)c).Enabled = !isDisable;
if (c.HasChildren)
ControlStatus(c, isDisable);
}
catch (Exception)
{ }
}