TextBox.TextChanged是否可触发而不使用Enter键提交表单? [英] Is TextBox.TextChanged triggerable without using Enter key to submit form?

查看:86
本文介绍了TextBox.TextChanged是否可触发而不使用Enter键提交表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络表单中有两个文本框:

- txtInitialValue

- txtCalculatedValue



当我填写txtInitialValue并按Enter键,我希望这种情况发生:

I have 2 textboxes in a web form:
- txtInitialValue
- txtCalculatedValue

When I fill out txtInitialValue and push Enter, I want this to happen:

txtCalculatedValue.Text = (myFloatParser.ToFloat(txtInitialValue.Text) * 2.5).ToString();





但是,每次按Enter键都会提交表单。我尝试禁用它,它的工作原理,但缺点是我不能再输入触发txtInitialValue.TextChanged事件。



如何禁用Enter键提交表单,同时允许我为文本框触发TextChanged事件?



However, the form gets submitted every time I push Enter. I tried disabling it, and it works, BUT the drawback is I cannot trigger the txtInitialValue.TextChanged event with enter anymore.

How do I disable the Enter key from submitting the form, while at the same time allowing me to trigger TextChanged event for a textbox?

推荐答案

使用 JavaScript

为您要按 Enter <的 TextBox 附加 onkeypress 事件/ code> key。

检查按下了哪个键。

如果输入 Key,则进行计算。
Use JavaScript.
Attach the onkeypress event for that TextBox on which you want to press Enter key.
Check which key is pressed.
If it is Enter Key, then do your calculation.


这篇关于TextBox.TextChanged是否可触发而不使用Enter键提交表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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