c# - Instead of making an if() for each control type, is there a cast that will allow me to dynamically set the type of control? -
I am running through my controls on this web page again and when to modify a piece of data data I am disabling other controls on the page, such controls include textboxes, listboxes and buttons. All of these controls, so there was a way to just set its properties universal data type cast control of any kind and capable then I was thinking protected void DisableSQRcontrols (Property Control page) {foreach (Control Ctrl in Page Ctrl.Controls) if (ctrl is text box) ((text box) ctrl). Competent = false; And if (ctrl button is) ((button) ctrl). Enabled = false; And if (ctrl listbox is) ((listbox ctrl). Enabled = false; And if (ctrl.Controls.Count> 0) DisableSQRcontrols (ctrl); } I protected void disabled DisablesSQRcontrols (Control page) {foreach (page control Ctrl.Controls Ctrl) to change the top like some Want to If ((ctrl is text box) || (ctrl is button) || (ctrl is listbox)) ((universal controlcode ctrl). Competent = false; And if (ctrl.Controls.Count> 0) DisableSQRc...