0

I've got a textbox name txtEmpcode.When it looses focus i want to show a alert message.I've written jquery for the above functionality,but its not working...

THis is my jquery

$(document).ready(function(){
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    //Raised before processing of an asynchronous postback starts and the postback request is sent to the server.
    prm.add_beginRequest(BeginRequestHandler);
    // Raised after an asynchronous postback is finished and control has been returned to the browser.
    prm.add_endRequest(EndRequestHandler);    
    AutoComp();//Function for autocomplete textbox        

    $("#<%=txtEmpCode.ClientID").change(function(){         
        alert("hai");
    });

});

Heres my asp.net textbox

<asp:TextBox ID="txtEmpCode" runat="server" Width="250px" ToolTip="Enter EmployeeCode" 
AutoPostBack="True"  ontextchanged="txtEmpCode_TextChanged"></asp:TextBox>
ksg
  • 3,927
  • 7
  • 51
  • 97

3 Answers3

3

at the first sign you skipped %>

$("#<%=txtEmpCode.ClientID%>").change(function(){         
        alert("hai");
    });
Anton Baksheiev
  • 2,211
  • 2
  • 14
  • 15
1

When a element lost the focus you could use the .blur() function in Jquery to capture the event. Example:

 $(document).ready(function () {
        $('#idElement').blur(function () {
           alert('i lost the focus \o/');
        });

});

Sorry the bad english.

0

Remove your ontextchanged="txtEmpCode_TextChanged" from your TextBox. Or remove your change event from your jQuery, and implement the method for txtEmpCode_TextChanged. Beware, the change event for a textbox doesn't handle all cases.

Here is some good info on detecting changed text in a textbox: How to detect a textbox's content has changed

Community
  • 1
  • 1
Gromer
  • 9,861
  • 4
  • 34
  • 55
  • How are you testing to see if it is firing? With `change`, you need to type in new text, and then tab out of the textbox to loose focus. It doesn't fire when you're still in the textbox. – Gromer Sep 27 '12 at 18:09
  • i've tested as per your comment and still not working.Im using multiview and update panel,is there any problem in this ??? – ksg Sep 27 '12 at 18:42