开发者

Disable a control using FindControl

开发者 https://www.devze.com 2023-01-30 11:29 出处:网络
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 \"Enable

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消