I’m trying to get the OnKeyPress event to work for a ASP.NET ListBox which renders itself as a SELECT element in HTML. After doing some search, a couple of site seems to suggest that it is supported, but the event just does not seem to trigger and call my JavaScript code. It seems to trigger for another edit box on the same page, but does not do it for the SELECT element.
I want to use the OnKeyPress event so I could retrieve the ASCII code, whereas OnKeyDown and OnKeyUp returns the key code instead.
I’m currently using IE7 and I was wondering if the OnKeyPress event is supported by SELECT elements?
Here is how I am doing it in the aspx file:
<asp:ListBox ID="myListBox" runat="server" Width="306px" SelectionMode="Single"
Rows="15" CssClass="myListBoxStyle" DataSourceID="myDataSource"
onchange="myListBoxOnChange(this)"
onkeypress="myListBoxOnKeyPress(this)" />
My bad. It seems that I had an
onkeydown="return false"in the ASPX code of my ListBox element which canceled theonkeypressevent from happening.