Errant PostBack - Numeric TextBox Javascript

P

Phillip Ian

I have a textbox that I'm trying to limit to numeric entry (damn you
Microsoft for not including it in .NET!)

I've found sample code and come up with this as a solution:

<asp:TextBox id="fldQty" runat="server" CssClass="ThreePlaceInput"
MaxLength="3" Text='<%# DataBinder.Eval(Container, "DataItem.Qty") %>'
onKeyPress="javascript:return AllowOnlyNumbers();">

The Javascript looks like this:

<script language='javascript'>
<!--
function AllowOnlyNumbers() {
return ((event.keyCode >= 48) && (event.keyCode <= 57)) ||
(event.keyCode = 13);
}
-->
</script>

Now, for some reason, pressing a key that isn't accepted by the
function (non-numeric) is causing a postback. Obviously, this isn't
the intended result.

Also, this method doesn't seem to work at all in Firefox or Opera.
Anything I can do there?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top