Friday, August 10, 2012

Asp.Net jQuery Textbox Disable


The jQuery library provides various options to work with Textboxes, in this post Asp.Net jQuery Textbox Disable, we shall see on how to Disable an Asp.net Textbox control.

We can disable a Textboxes using jQuery as follows.

$('#txtEnableDisable').prop("disabled", true);

Example
Create a new HTML/ASPX page 
Copy the below code.
Change the mapping of the jQuery file 
jquery-1.7.2.js to map to your local drive.
Run the application, Click on the Disable Radio Button to set the Disable Property



<html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">
    <title>TextBox</title>
    <link type="text/css"
href="Stylesheet.css"
rel="Stylesheet" />
    <script
type="text/javascript"
src="JavaScript/jquery-1.7.2.js"></script>
    <script
type="text/javascript"
language="javascript">
        $(document).ready(function() {
            //
            // TextBox Disable
            $('#radEnableDisable_1').click(function() {
                if ($('#radEnableDisable_1:checked').is(':checked')) {
                    $('#txtEnableDisable').prop("disabled", true);
                }
            });  
        });
    </script>
</head>
<body>
    <form id="frmTextBox" runat="server">
    <div id="pageControls">
        <table>
                        <tr>
                <td>Textbox (Enable/Disable)</td>
                <td>
                    <asp:TextBox id="txtEnableDisable" 
                                 runat="server"></asp:TextBox> 
                    <asp:RadioButtonList
                                 ID="radEnableDisable"
                                 runat="server"
                                 RepeatDirection="Horizontal">
                        <asp:ListItem
                                 Value="Enable"
                                 Text="Enable"></asp:ListItem>
                        <asp:ListItem
                                 Value="Disable"
                                 Text="Disable"></asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr> 
  </table>
    </div>
    </form>
</body>
</html>



Search Flipkart Products:
Flipkart.com

No comments: