Tuesday, July 27, 2010

Disable all controls of asp.net page

call it like this: DisableControls(Page ,false);

below code is to disable all controls of a asp.net page.

protected void DisableControls(Control parent,bool status)
{
foreach (Control ctrl in parent.Controls)
{

if (ctrl is TextBox)

((TextBox)ctrl).Enabled = status;

else if (ctrl is Button)

((Button)ctrl).Enabled = status;

else if (ctrl is RadioButton)

((RadioButton)ctrl).Enabled = status;

else if (ctrl is ImageButton)

((ImageButton)ctrl).Enabled = status;

else if (ctrl is CheckBox)

((CheckBox)ctrl).Enabled = status;

else if (ctrl is DropDownList)

((DropDownList)ctrl).Enabled = status;

else if (ctrl is HyperLink)

((HyperLink)ctrl).Enabled = status;

DisableControls(ctrl,status);
}
}

Share This!


No comments:

Powered By Blogger · Designed By Seo Blogger Templates