2

How do I enable a textbox on a link button click, I'm disabling the textbox in the html

Here is the jquery code I'm trying to use:

<script type="text/javascript" language="javascript">
        $(document).ready(function () {
        $('#lEdit').click(function () {
            $('#CorporationName').removeAttr('disabled');
        });
    });
</script>

<asp:LinkButton ID="lEdit" runat="server" ClientIDMode="Static" >Edit</asp:LinkButton>
<asp:Label ID="lblCorporationName" runat="server" Text="Corporation Name" Width="130px"></asp:Label>
<asp:TextBox ID="CorporationName" runat="server" Width="250px" ClientIDMode="Static" Enabled="false"></asp:TextBox>

2 Answers 2

5

It looks like you're doing it right. If that isn't working, try:

$('#CorporationName').prop('disabled', false);
Sign up to request clarification or add additional context in comments.

Comments

1

While setting a property to false or even null might work, you might want to try jQuery's removeProp() function. It's designed to do just that.

Description: Remove a property for the set of matched elements.

$('#CorporationName').removeProp('disabled');

Be aware, once you remove the property in this way, you won't be able to disable the textbox again.

1 Comment

Actually, it is recommended that you don't use it for that purpose. From .removeProp(): Note: Do not use this method to remove native properties such as checked, disabled, or selected. This will remove the property completely and, once removed, cannot be added again to element. Use .prop() to set these properties to false instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.