TextBox.TextChanged是否可触发而不使用Enter键提交表单? [英] Is TextBox.TextChanged triggerable without using Enter key to submit form?
问题描述
我在网络表单中有两个文本框:
- 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 theonkeypress
event for thatTextBox
on which you want to pressEnter
key.
Check which key is pressed.
If it isEnter
Key, then do your calculation.
这篇关于TextBox.TextChanged是否可触发而不使用Enter键提交表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!