0

I am new to this kind of programming. I am trying to enable a Link Button on enter of any text in a ASP Text box. Basically it is a search text box when it has text the Search link should be enabled otherwise it should be disabled. The Search Link is a Link Button.

I have this code :- Text box:

<asp:TextBox ID="txtSearch" Width="100%" OnKeyUp='javascript:SetButtonStatus();' runat="server"></asp:TextBox>

Search Link Button:

<asp:LinkButton ID="lbtnSearch" runat="server" onclick="lbtnSearch_Click" ClientIDMode="Static">Search</asp:LinkButton>&nbsp;

JS Function :-

 function SetButtonStatus() {
        debugger;
        var searchtxt = document.getElementById('<%=txtSearch.ClientID%>').value;
        if (searchtxt.length >= 1) {
            document.getElementById('<%=lbtnSearch.ClientID%>').disabled = "";

        }
        else {
            document.getElementById('<%=lbtnSearch.ClientID%>').disabled = "disabled";

        }
    }

But this is unfortunately not working. The link button does not get enabled on entry of text in text box.

Any help is appreciated.

abhu85
  • 33
  • 3

1 Answers1

0

i've no knowledge about ASP, but in JavaScript the disabled property have to be true or false

<input type="input" id="txtSearch" OnKeyUp="toggleable()">
<input type="input" id="lbtnSearch" disabled>
<script>
function toggleable()
{
    var txtinput = document.getElementById("txtSearch").value;
    document.getElementById("lbtnSearch").disabled = (txtinput.length) ? false : true;
}
</script>
Scriptkiddy1337
  • 792
  • 4
  • 9
  • The disabled property is set to true or false before .Net 4.0 ... In the new versions disabled value can be disabled or "" ..depending upon true or false. – abhu85 Mar 27 '15 at 20:12
  • In .Net there is an `Enabled` property for this. In JS `element.setAttribute('disabled', "disbaled");` only works cause in JScript all filled `string` returns `true`, but for enable u need to set `element.setAttribute('disabled', false);` – Scriptkiddy1337 Mar 27 '15 at 21:31