Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Wonder if anyone knows why this does now work:

XML
<asp:TextBox Width="50" ID="TB1" runat="server" onKeyPress="CatchEnter(event.keyCode)"/>

<asp:DropDownList runat="server" onKeyPress="CatchEnter(event.keyCode)" />

    <div style="display:none">
    <asp:Button ID="btnLogin"
                runat="server"
                OnClick="btnLogin_Click" />
    </div>

<script type="text/javascript">
    function CatchEnter(e) {
        if (e == 13) {
            alert("caught");
        }
    }
</script>


So - we have an TextBox and DropDownList. Both have onKeyPress event handler, but for some reasons on FireFox pressing "Enter" in TextBox works and does not on DropDownList. With DropDownList I have to press ALT + Enter to make it happen? Though it works on IE and Chrome.

Anyone knows a workaround?

Thanks!
Posted
Comments
Ajith K Gatty 28-May-14 6:05am    
Hi..I checked your code. Does it work properly on Chrome?? Dont you have to hit enter twice to trigger the event?
MK-Gii 28-May-14 6:35am    
Yes it works - single "enter" press works fine. But not with DropDownList.

Please try to use "KeyDown" instead of "KeyEnter"..

Try it If its work in your case please accept it...
 
Share this answer
 
try below code
HTML
onKeyPress="CatchEnter(event.keyCode? event.keyCode : event.charCode)" 
 
Share this answer
 
v3
Tried everything that I could think of... but only this worked to catch real Enter button press on <asp:dropdownlist xmlns:asp="#unknown">

XML
window.onkeydown = function (e) {
        if (e.keyCode == 13)
        {
            document.getElementById("<%=MyButtonID.ClientID %>").click();
        }
    }


Not sure why, but with windows.onkeypress it does not work with FireFox v29...
Anyways - hope someone finds this useful.

Cheers!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900