C# 在asp.net中禁用div内的所有控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9721025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable all controls within div in asp.net
提问by William Contestabile
Can someone tell me how I can disable all controls within a div?
有人能告诉我如何禁用 div 中的所有控件吗?
The div is set to runat="server"
div 设置为 runat="server"
Many thanks for your help.
非常感谢您的帮助。
采纳答案by CAbbott
回答by Andreas
Since the OP asked how to do this with a DIV with runat="server" I thought I'd add a solution for that:
由于 OP 询问如何使用带有 runat="server" 的 DIV 来执行此操作,因此我想我会为此添加一个解决方案:
myDiv.Attributes.Add("Disabled", "");
That's what a Panel with Enabled = false is rendered as anyway, and requires no change in your code. There is no need for a attribute value (like True), since the presence of the attribute itself is enough.
这就是具有 Enabled = false 的 Panel 无论如何呈现的内容,并且不需要更改您的代码。不需要属性值(如True),因为属性本身的存在就足够了。
Note: to enableyour DIV again, you can't just set the Disabledattribute to False. You have to remove the attribute alltogether:
注意:要再次启用您的 DIV,您不能将Disabled属性设置为False。您必须完全删除该属性:
myDiv.Attributes.Remove("Disabled");

