Disable a control using FindControl
I have a situation where I need to dynamically disable certain co开发者_运维问答ntrols. I will not be knowing the type of control. I tried to use FindControl(""), but this does not have the "Enabled" property, it only has "Visible" property.
Kindly let me know how this can be done.
Thanks in advance.
The Enabled property is only exposed by the WebControl class and its descendants. You'll need to ensure the control returned by FindControl() is a web control and cast it as such before disabling it:
WebControl webControl = FindControl("yourControlId") as WebControl;
if (webControl != null) {
webControl.Enabled = false;
}
精彩评论