adsense

Friday, June 2, 2017

asp.net textbox Enter key press focus to next control

The default behavior when  pressing Enter key on textbox is to fire the form submit event.
 This default behavior can be overridden and force the input to be advanced to the next control as shown below.

<script type="text/javascript">
 
 function pageLoad(){
 //you can use the control id or class
    $("#<%=txtName.ClientID%>").keypress(function (event) {
                var Text = $(this).val();
                if (event.which == 13) {
                    event.preventDefault();
                    $("#<%=txtPwd.ClientID%>").focus();
                }
            });
 
     $("#<%=txtPwd.ClientID%>").keypress(function (event) {
                var Text = $(this).val();
                if (event.which == 13) {
                    event.preventDefault();
                    $("#<%=butnLogin.ClientID%>").focus();
                }
            });
 } 
 
</script> 
 
 


No comments:

Post a Comment