功能描述:把一个Form里面的控件禁用,例外的控件可通过参数控制
Code
public static void DisableInputControl(params Control[] excludeControls)
{
Page page = HttpContext.Current.Handler as Page;
if (page == null)
return;
DisableChildInputControl(page, excludeControls);
}
public static void DisableChildInputControl(Control control, params Control[] excludeControls)
{
foreach (Control child in control.Controls)
{
if (excludeControls.Length > 0)
{
bool exists = false;
foreach (Control excludeControl in excludeControls)
{
if (excludeControl.Equals(child))
{
exists = true;
break;
}
}
if (exists)
continue;
}
if (child is TextBox)
{
((TextBox)child).Enabled = false;
}
else if (child is Button)
{
((Button)child).Enabled = false;
}
else if (child is DropDownList)
{
((DropDownList)child).Enabled = false;
}
//递归
DisableChildInputControl(child, excludeControls);
}
}
public static void DisableInputControl(params Control[] excludeControls)
{
Page page = HttpContext.Current.Handler as Page;
if (page == null)
return;
DisableChildInputControl(page, excludeControls);
}
public static void DisableChildInputControl(Control control, params Control[] excludeControls)
{
foreach (Control child in control.Controls)
{
if (excludeControls.Length > 0)
{
bool exists = false;
foreach (Control excludeControl in excludeControls)
{
if (excludeControl.Equals(child))
{
exists = true;
break;
}
}
if (exists)
continue;
}
if (child is TextBox)
{
((TextBox)child).Enabled = false;
}
else if (child is Button)
{
((Button)child).Enabled = false;
}
else if (child is DropDownList)
{
((DropDownList)child).Enabled = false;
}
//递归
DisableChildInputControl(child, excludeControls);
}
}