Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NETJavascript
I want to when i press enter focus should not lost from current text box
or page load event should not call
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <script src="Scripts/validation.js" type="text/javascript"></script>
    <script language="javascript"  type="text/javascript">

        function EmpHelp() {
            popup ='EmpMstrHelp.aspx', null, 'height=320,  width=320,status= no, resizable= no, scrollbars=no, toolbar=no,location=center,menubar=no, top=100, left=300');
            common = "EmpHelp"
            return false;
        function EmpId() {
           // alert('ss');
       //  return (event.keyCode!=13);
         var key = event.keyCode;
        // alert(key);
         if (key == 113 && key != 13) {
             document.getElementById('<%=btnEmpHelp.ClientID %>').click();
         else {
           //document.getElementById('<%=txtEmpId.ClientID %>').focus();//its also not working and i want for all text box not for only specific one 
         //I Want my focus should not lost and page load event should not call if Enter pressed 
            // return false;
        <td align="right" style="color: #000000; font-weight: bold">
            <span style="color:Red">*</span>Employee Id
        <td align="left" style="color: #000000; font-weight: bold">
            <asp:TextBox ID="txtEmpId" runat="server" Width="50px" MaxLength="5" TabIndex="1" 
                    AutoPostBack="True" ontextchanged="txtEmpId_TextChanged"></asp:TextBox>
             <asp:Image ID="btnEmpHelp" runat="server" ImageUrl="~/help.gif" Width="20px" />
protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            clear();//my fuctn that clear all values 
            txtEmpId.Attributes.Add("onkeypress", "javascript:return alphanumeric(event);"); //lets say i have preform some validations
            txtEmpId.Attributes.Add("onkeydown", "EmpId()"); //one pop up help aapers 
            btnEmpHelp.Attributes.Add("onclick", "EmpHelp()"); //that help button
  protected void txtEmpId_TextChanged(object sender, EventArgs e)
      //lets say my Populated code
Posted 17-Nov-12 18:14pm
ridoy at 18-Nov-12 0:48am
so what's thee problem here?
Member 9472024 at 18-Nov-12 1:00am
page getting submitted on press enter on textbox
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

function stopRKey(evt) {
   var evt = (evt) ? evt : ((event) ? event : null);
   var node = ( ? : ((evt.srcElement) ? evt.srcElement : null);
   if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
document.onkeydown = stopRKey;
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Using jquery ,we have done something simmiler to yours. we have place
        if(event.keyCode == 13) {
          return false;
bunch lines of code in doucment.ready.
it basically suppress enter.
sushantraje2000 at 18-Nov-12 23:09pm
it will disable button behavior also
deepak.m.shrma at 18-Nov-12 23:24pm
yup!! it disable button bhvr.. that is what you want. Button default behavior is to submit form. that is what you mention in type=submit. you have to submit your form onclick event.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

ascii code for 'enter' key is 13 use this no and put 'return false' at end of the statement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
0 Sergey Alexandrovich Kryukov 680
1 OriginalGriff 379
2 Manas Bhardwaj 350
3 Abhinav S 293
4 Sampath Lokuge 245
0 Sergey Alexandrovich Kryukov 7,647
1 OriginalGriff 4,287
2 Peter Leow 3,681
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107

Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid