0

Hi all

I used master page in my application and there is a button and text box on it which redirects user to another page. There is also another button and text box for user to login in to his control panel. When i fill up the login form and press enter, button which is at top which redirects me to another page is called but not login button.

I used below java script function to handle enter key press

function controlEnter(obj, event) {
            var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
            if (keyCode == 13) {
                __doPostBack(obj, '');
                return false;
            }
            else {
                return true;
            }
        }

Above function is called by adding attribute to textbox in page load

txtUserName.Attributes.Add("onkeypress", "return controlEnter('" + BtnLoginUser.UniqueID + "', event)");

Kindly tell me what am i doing wrong. How can i associate enter key press to the correct
button click.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Ramesh S
0

Hi,

Set the defaultbutton property in the <form> tag to the ID of button that should get fired when user press enter key to submit the form.

For example,

<form id="form1" runat="server" defaultbutton="btnLogin">
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.