title: Difference between onkeypress and onkeydown in asp.net
body: <p>I have a form with a default button set.So when i press enter,form is submitted regardless of the focus. My requirement is when focus is inside fileupload control and enter is pressed,instead of submitting the form show browse dialog. So I created a panel and attached a onKeyPress event to this panel</p>
  
  <pre><code> fileUploadDocument.Attributes.Add("onkeyPress", "return ByPassEnter(event);");
  
  &lt;asp:Panel ID="fileUploadDocument" runat="server"&gt;
          &lt;div&gt;
              &lt;uc2:FileUploadControl ID="ucdocxUploadControl" runat="server" ErrorMessageNoFileSelected="Please select a file for upload."
                  ValidationGroup="BrandLogoFileUpload" /&gt;
          &lt;/div&gt;
  &lt;/asp:Panel&gt;
  
  
  
  function ByPassEnter(e) {       
         var evt = (e) ? e : window.event;
          var key = (evt.keyCode) ? evt.keyCode : evt.which;
         if (key == 13) {
              document.getElementById('&lt;%=ucdocxUploadControl.BaseFileUploadControl.ClientID %&gt;').click();
              CancelDefault(evt);
          }
      }
  
      function CancelDefault(e) {        
          e.cancel = true;
          if (e.preventDefault) {
            e.preventDefault();                   
          }
        e.returnValue = false;
      }
  </code></pre>
  
  <p>When i press enter on fileupload control, browse dialog shows up and when i choose a file or hit cancel on browse dialog,postback happens. e.returnValue = false should prevent the postback but even then postback happens.</p>
  
  <p>However if i change onkeypress to onkeydown,everything works and postback doesnot happen.Can somebody tell me the difference in these events and why postback is happening in onkeypress.</p>