0

I have 3 asp.net text box and an html input botton, when enter is pressed in any of the above text boxes input button click event must be fired.My code is

    <li class="right2">
        <asp:TextBox ID="txtPassportNumber" ClientIDMode="Static" MaxLength="20" CssClass="textEntry"
            runat="server"></asp:TextBox>
    </li>


    <li class="left"><label>First Name</label></li>
    <li class="right2">
        <asp:TextBox ID="txtFName" ClientIDMode="Static" MaxLength="20" CssClass="textEntry" runat="server"></asp:TextBox>

    </li>
    <li class="left"><label>Last Name</label></li>
    <li class="right2">
        <asp:TextBox ID="txtLName" ClientIDMode="Static" MaxLength="20" CssClass="textEntry" runat="server"></asp:TextBox>
    </li>

    <input type="button" id="btnSearch" clientidmode="Static" class="search button formbutton"
                value="Search" validationgroup="SearchPanelSubmit" runat="server" />

I have write the following jquery code

$(document).ready(function () {
       if ($('#txtPassportNumber').keypress(function (e) {
            if (e.keyCode == 13)
                $('#btnBasicSearch').click();
       }));
}

I have used multiple if 's in jquery code but the button is not working when more then 1 text box has some text in it.How to handle enter event for multiple text boxes ?

3 Answers 3

1

I suppose you need a functionality to postback when the content in the textbox is changed. One quick way of doing this would be to set the AutoPostBack property of the textbox to true and write an event handler for the textbox change event.

This causes postback to happen when the following event occurs:
1. When the content changes and focus is lost from the textbox by pressing the tab button or clicking on some other control.
2. When enter is pressed while focus is on the textbox.

No additional code is required to perform this functionality. Hope this is what you intend to achieve.

Sign up to request clarification or add additional context in comments.

Comments

0

Javascript way

document.onkeypress = KeyCheck;
        function KeyCheck() {
            var key = event.keyCode;
            switch (key) {
                case 13: 
                    //Enter key
                    //Call your function here
                    break;
            }
        }

Comments

0

write your html code inside the form tag and change input type="button" to type="submit"

Comments

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.