How to Enable and Disable all Input control using jQuery in ASP.Net?
Sometimes, we will have requirements to disable all the input control in aspx page to prevent users from providing some inputs. This little jquery snippet will help us to disable all the input controls in our page to be disabled except button control.
Refer below,
<head runat="server"> <title></title> <script src="_scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script language="javascript"> $(document).ready(function() { $("#btnReset").toggle(function() { $("INPUT:not(INPUT[type=button]),SELECT,TEXTAREA").attr("disabled", "disabled"); }, function() { $("INPUT:not(INPUT[type=button]),SELECT,TEXTAREA").removeAttr("disabled"); }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> </asp:DropDownList> <asp:ListBox ID="ListBox1" runat="server"> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:ListBox> <asp:CheckBox ID="CheckBox1" runat="server" Text="eeee" /> <asp:RadioButton ID="RadioButton1" runat="server" Text="eeee" /> <asp:CheckBoxList ID="CheckBoxList1" runat="server"> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:CheckBoxList> <asp:RadioButtonList ID="RadioButtonList1" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:RadioButtonList> <input ID="btnReset" type="button" value="ResetAll" /> </div>
In the above code, all the input controls will get disabled on click of the reset button and it will get enabled on the next click (toggle).
Happy Coding!!
|
|