views:

2797

answers:

11

Hi,

When you create an aspx page as this one:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

    </div>
    </form>
</body>
</html>

how can you avoid the beep sound that happens when you are in a textbox and hit enter.

On the other hand I would like to handle the enter onkeypress event.

Tx!

A: 

What browser, OS are you using?

Chuck Conway
friendly reminder - you entered this message in a box clearly labeled 'your answer', and yet it obviously isn't an answer, it's a question - the answers aren't for created a threaded forum - style discussion. Thanks!
matt lohkamp
A: 

Internet Explorer 7.0/8.0Beta and Windows Vista SP1

But it is more related to the browser.

A: 

You have to turn it off in your sound preferences on your operating system. It's an Internet Explorer thing.

Joe Philllips
A: 

This would be a web solution, so I won't be able to disable it for every user. Is there any way to avoid it?

friendly reminder - you entered this message in a box clearly labeled 'your answer', and yet it obviously isn't an answer, it's a question - the answers aren't for created a threaded forum - style discussion. Thanks!
matt lohkamp
+2  A: 

If it's related to the browser that your audience is using, then they're used to it happening, because it happens on every other site besides yours. I'd say it's not worth worrying about - kind of like people with JavaScript turned off. They know they've got it turned off, and they're accustomed to sites lacking certain functionality as a result. You can't force them to turn it on, and you can't force them to turn the sound thing off. It's one of those experience comprises you've got to accept in web apps.

matt lohkamp
nor what I expected, as I would like to get the same experience for all my users
A: 

I haven't done much of anything in asp, but my first thought is that it would be similar to a Winforms application. My first step in solving it would be to set the key (code, keycode, whatever it's named in the event) var to #0 or null, as well as any vars such as e.handled in the event call prior to returning.

+1  A: 

Put this in your form tag onkeypress="if(event.keyCode==13)return false;"

+2  A: 

First of all, it is NOT standard behavior to get a beep when pressing enter in a textbox on a webpage. Try Google's search page, or for that matter try the Name, Email, and Home Page fields at the bottom of this page. None of them beep when pressing enter - in any browser.

To prevent the beep, handle the onKeyDown event on your <INPUT> tag and return false if the enter key is pressed:

<input type="text" name="TextBox1" value="" onKeyDown="return StopBeepOnEnter(event)" />

<script type="text/javascript">
    function StopBeepOnEnter(event)
    {
     if (event.keyCode == 13)
     {
      // Do Whatever...

      return false; // This stops the beep
     } 
    }
</script>

And here is the same thing using jQuery (I've actually tested this and it solved the problem for me):

<script type="text/javascript">
    $("#<%=TextBox1.ClientID %>").keydown(function(event)
    {
     if (event.keyCode == 13)
     {
      // Do Whatever...

      return false; // This stops the beep
     }
    });
</script>

I found the solution on this thread - credit to Tharn Jaggar:

http://codingforums.com/showthread.php?t=36491

A: 

Hi,

Finally I am able to disable the beep sound on all the components of the page while pressing Enter key in textfield or combo or any component, which was required. What I did is I added [onkeypress="if(event.keyCode==13)return false;"] in my body tag like given below:

   <body onkeypress="if(event.keyCode==13)return false;">

I used above code in my GWT GXT Application.

Krishan Babbar

Krishan Babbar
A: 

KeyPressEvent.preventDefault() seems to do the trick in GWT

Doug Nickerson