Click here to Skip to main content
Rate this: bad
good
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 = window.open('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 
             //return;
         //I Want my focus should not lost and page load event should not call if Enter pressed 
          
            // return false;
         }
        }
        
        
 </script>  
    
    
    
<table>
    <tr>
        <td align="right" style="color: #000000; font-weight: bold">
            <span style="color:Red">*</span>Employee Id
        </td>
        <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" />
            Search
        </td>
    </tr>
 
 
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
Comments
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
good
Please Sign up or sign in to vote.

Solution 4

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

Solution 1

Using jquery ,we have done something simmiler to yours. we have place
$(window).keydown(function(event){
        if(event.keyCode == 13) {
          event.preventDefault();
          return false;
        }
      });
bunch lines of code in doucment.ready.
it basically suppress enter.
  Permalink  
Comments
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
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 940
1 OriginalGriff 543
2 Abhinav S 253
3 thatraja 245
4 Emre Ataseven 200
0 Sergey Alexandrovich Kryukov 8,282
1 OriginalGriff 4,750
2 Peter Leow 3,784
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


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