1

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>
THelper
  • 15,333
  • 6
  • 64
  • 104
French Boy
  • 1,471
  • 3
  • 18
  • 23
  • this may help: [How do I disable all controls in ASP.NET page?][1] [1]: http://stackoverflow.com/questions/505353/how-do-i-disable-all-controls-in-asp-net-page – Waqas Aug 02 '11 at 07:14

2 Answers2

2

Using JavaScript you may do something like this :

var controls = document.getElementById("<%=panel1.ClientID%>").getElementsByTagName("input");

for (var i = 0; i < controls.length; i++)
     controls[i].disabled = true;

Note that ASP.Net produces dynamic Id's for server side controls (panel here ) , that tends to use document.getElementById("<%=panel1.ClientID%>") above.

Sandeep Pathak
  • 10,567
  • 8
  • 45
  • 57
1

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:

<asp:Panel ID="Panel1" runat="server" Enabled="false" >
    <asp:CheckBox ID="CheckBox1" runat="server" /> 
</asp:Panel>

You could also easily fix this with jquery (client side):

$('#mypanelClientID input[type=checkbox]').attr('disabled', true);
Willem
  • 5,364
  • 2
  • 23
  • 44