开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜