如何同时启用/禁用多个控件?
我有许多复选框 HTML 控件在服务器上运行,我想一起禁用和启用它们。 我尝试将它们设置在 ASP.Net 面板中并将面板设置为禁用,但它们保持启用状态。
有什么想法吗?
代码
<asp:Panel runat="server" ID="PrivilegesCheckList" >
<input id="adminPrivilegeCheckBox" type="checkbox" runat="server" />
<asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:Resource, itemAdminPrivilege%>" />
<br />
<input id="accountPrivilegeCheckBox" type="checkbox" runat="server" clientidmode="Static" />
<asp:Literal ID="Literal2" runat="server" Text="<%$ Resources:Resource, itemAccountManagerPrivilege%>" />
<br />
<input id="employeePrivilegeCheckBox" type="checkbox" runat="server" clientidmode="Static" />
<asp:Literal ID="Literal3" runat="server" Text="<%$ Resources:Resource, itemEmployeeManagerPrivilege%>" />
<br />
<input id="orgChartPrivilegeCheckBox" type="checkbox" runat="server" clientidmode="Static" />
<asp:Literal ID="Literal4" runat="server" Text="<%$ Resources:Resource, itemOrgChartPrivilege%>" />
</asp:Panel>
I have many checkBoxes HTML controls runat server, I want to disable and enable them together.
I've tried to set them in an ASP.Net Panel and set the panel disabled, but they stayed enabled.
Any idea ?
The code
<asp:Panel runat="server" ID="PrivilegesCheckList" >
<input id="adminPrivilegeCheckBox" type="checkbox" runat="server" />
<asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:Resource, itemAdminPrivilege%>" />
<br />
<input id="accountPrivilegeCheckBox" type="checkbox" runat="server" clientidmode="Static" />
<asp:Literal ID="Literal2" runat="server" Text="<%$ Resources:Resource, itemAccountManagerPrivilege%>" />
<br />
<input id="employeePrivilegeCheckBox" type="checkbox" runat="server" clientidmode="Static" />
<asp:Literal ID="Literal3" runat="server" Text="<%$ Resources:Resource, itemEmployeeManagerPrivilege%>" />
<br />
<input id="orgChartPrivilegeCheckBox" type="checkbox" runat="server" clientidmode="Static" />
<asp:Literal ID="Literal4" runat="server" Text="<%$ Resources:Resource, itemOrgChartPrivilege%>" />
</asp:Panel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 JavaScript,您可以执行以下操作:
请注意,ASP.Net 为服务器端控件(此处为面板)生成动态 Id,它倾向于使用上面的 document.getElementById("<%=panel1.ClientID%>")。
Using JavaScript you may do something like this :
Note that ASP.Net produces dynamic Id's for server side controls (panel here ) , that tends to use document.getElementById("<%=panel1.ClientID%>") above.
将面板设置为禁用将适用于像 CheckBox 这样的 asp 控件,但不适用于带有 runat=server 的输入。此复选框被禁用,因为面板已 Enabled=false:
您也可以使用 jquery(客户端)轻松修复此问题:
Setting the Panel to disabled would work for asp Controls like CheckBox but not for an input with runat=server. This checkbox is disabled because the panel has Enabled=false:
You could also easily fix this with jquery (client side):