One way, you could use a params
array:
public static void EnableControls(bool enable, params WebControl[] controls)
{
foreach (WebControl c in controls)
{
if (c != null) c.Enabled = enable;
}
}
Note that
- I return
void
(nothing) since you just set a property of already available controls. Returning them would be pointless - I have added a parameter
enable
which allows to enable or disable the controls - I have changed it to acceppt
WebControls
since that's the class with theEnabled
property, on this way you can use it for other controls likeTextBox
orLabel
as well, so your method is more useful public static
makes it also more usable, you don't need to access the instance of the surroundingPage
-class anyway.
You can call it with single DropDownList
s:
EnableControls(false, dropdown1, dropdown2, dropdown3);
or with an array (pseudo code):
var manyDropDowns = new DropDownList[]{ dropdown1, ..., dropDown999999 };
EnableControls(false, manyDropDowns);