禁用默认按钮或在asp.net C#回车键 [英] disabling default button or enter key in asp.net c#

查看:1055
本文介绍了禁用默认按钮或在asp.net C#回车键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,用户在扫描条形码形式,条码阅读器自动在值回车导致表单提交,因为浏览器选择的第一个按钮为默认值。我怎样才能从当在文本框entring一个值时,按下回车键禁用发生什么?

I have a form where users scan in a barcode, the barcode reader automatically enters a carriage return in the value causing the form to submit since the browser chooses the first button as the default. How can I disable anything from happening when the enter key is pressed when entring a value in that textbox?

推荐答案

您需要使用JavaScript来做到这一点。在您的标记文本框,添加的onkeydown处理,像这样:

You'll need to do it with javascript. In your markup for the text box, add an onkeydown handler like so:

<asp:TextBox ID="TextBox1" runat="server"
   onkeydown = "return (event.keyCode!=13);" >
</asp:TextBox>

这将返回false如果该键是输入键,将取消表单提交。

This will return false if the key was the enter key, which will cancel the form submission.

这篇关于禁用默认按钮或在asp.net C#回车键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆