How to Disable/enable form elements using jQuery in ASP.NET

Leave a Comment


Using jQuery, you can easily disable form elements by setting the disabled attribute value of a form element to disabled. To do this, we simply select an input, and then using the attr() method, we set the disabled attribute of the input to a value of disabled.

<asp:Button ID="button" runat="server" Text="Click me" />
<script>
        (function ($) {
            $('#<%=button.ClientID %>').attr('disabled', 'disabled');
        })(jQuery);
</script>


To enable a disabled form element, we simply remove the disabled attribute using removeAttr() or set the disabled attribute value to be empty using attr().

<asp:Button ID="button" runat="server" Enabled="false" Text="Click me" />
<script>
        (function ($) {
            $('#<%=button.ClientID %>').removeAttr('disabled');
        })(jQuery);
</script>



0 comments:

Post a Comment