Skip to content

Handle enter key press with two button.

amit shukla

Asked Oct 24, 2016, 11:20 PM EDT3 answers
Share
LinkedInX
hello friends
Today i am facing a problem given below.
 
in asp.net page , we take two button and one textbox on a asp.net page.
we want to manage enter key press on textbox , but when we press enter key on textbox
then automatically another button click event is call and textbox key up event is not call .
so please help this.
example :
 
<asp:TextBox ID="txtProjectName" runat="server" placeholder="Project Number"></asp:TextBox>
 
<asp:Button runat="server" ID="btnSerach" OnClientClick="return vallidateFields();" OnClick="btnSerach_Click" />
 
<asp:Button ID="txtY" class="btn blue" Text="Yes"  runat="server" OnClientClick="return vallidatePopUpFields();" OnClick="txtY_Click" /> 
 
when we press enter on textbox then call button click event but we want to call below code
 
JavaScript
 $('#<%=txtProjectName.ClientID%>').keyup(function (e) {
                debugger
                if(e.keyCode == 13)
                {

     $('#<%=btnSerach.ClientID%>').click();

                }

            });
 

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    o handle enterkey in textbox key press event and call another functionality in key up event.
    To check below code:
    keypress:
    $('#txtSearchList').keypress(function (event) { return event.keyCode != 13; });
    keyup:
    $('#txtSearchList').keyup(function () { To implement your code. }
    0
  • 0
    hi ankur
    thanks for your suggestion.
    but my problem is different,
    in my case when we press enter key on textbox then automatically call button click event
    event not goes textbox keyup event.
    like my text box is define above and when press enter key on this then keyup event not call
    it call automatically button click event
    0
  • 0
    From form level restricted [enter key value] key code value in java script.
    $('#formName').keypress(function (event) { return event.keyCode != 13; });
    0