JQuery to Enable Disable a Form Element TextBox Button Control in Asp.Net C# VB.Net

Some times we need to enable or disable Asp.Net controls to make an user friendly interface. Some times needs to do the same thing based on condition. In this article I will explain “How one can Enable or Disable Asp.Net TextBox and Button Control using JQuery means from Client Side“. For simplicity I am avoiding condition based enabling or disabling. Hope you can do it by following the below example.

Example to Implement:
Jquery to Disable Enable a Form Element TextBox Button in Asp.Net Csharp VB.Net

The HTML Markup:

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /><br />
    <asp:Button ID="Button1" runat="server" Text="Enable Disable Me" /><br />
    <hr />
    <asp:Button ID="Button2" runat="server" Text="Disable TextBox and Button" />
    <asp:Button ID="Button3" runat="server" Text="Enable TextBox and Button" />

Note: Here I have used 2 Button Controls. On fore disabling the TextBox and a Button Control and another one for enabling those controls.

JQuery code to Disable the Form Element:

<script type="text/javascript">
    $(document).ready(function () {
        $('#<%=Button2.ClientID %>').click(function () {
            $('#<%=TextBox1.ClientID %>').attr('disabled', 'disabled');
            $('#<%=Button1.ClientID %>').attr('disabled', 'disabled');
            return false;

JQuery code to Enable the Form Element:

<script type="text/javascript">
    $(document).ready(function () {
        $('#<%=Button3.ClientID %>').click(function () {
            $('#<%=TextBox1.ClientID %>').removeAttr('disabled');
            $('#<%=Button1.ClientID %>').removeAttr('disabled');
            return false;

Now run the project. Hope you can enable disable form controls using JQuery.

Note: For JQuery 1.6 & above you can use below properties also:

$('#<%=TextBox1.ClientID %>').prop('disabled', true);
$('#<%=Button1.ClientID %>').prop('disabled', false);

Download Code Example C#        Download Code Example VB.Net

Posted in .Net, Asp.net, C#, Client, JQuery, VB.Net

Leave a Reply

Your email address will not be published. Required fields are marked *

AlphaOmega Captcha Classica  –  Enter Security Code