I'm iterating through my controls on this web page and when a button is pressed to modify a piece of a data, I'm disabling the other controls on the page. Such controls consist of TextBoxes, ListBoxes, and Buttons. All of these controls have the Enable property so I was wondering if there was a way to just cast the control to some kind of universal data type and set its property of enabled.
protected void DisableSQRcontrols( Control Page )
{
foreach ( Control ctrl in Page.Controls )
if ( ctrl is TextBox )
((TextBox)ctrl).Enabled = false;
else if ( ctrl is Button )
((Button)ctrl).Enabled = false;
else if ( ctrl is ListBox )
((ListBox)ctrl).Enabled = false;
else if ( ctrl.Controls.Count > 0 )
DisableSQRcontrols( ctrl );
}
I'd like to change the top to something like
protected void DisableSQRcontrols( Control Page )
{
foreach ( Control ctrl in Page.Controls )
if ( ( ctrl is TextBox ) ||
( ctrl is Button ) ||
( ctrl is ListBox ) )
((UniversalControlCast)ctrl).Enabled = false;
else if ( ctrl.Controls.Count > 0 )
DisableSQRcontrols( ctrl );
}