使用时如何触发功能在文本框上按Enter [英] How to fire function when use press enter on textbox
本文介绍了使用时如何触发功能在文本框上按Enter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在json响应中创建了一个html字符串,该字符串创建了一个文本框,并且我已经将它附加到onkeypress函数上,但是我的问题是我的onkeypress enter函数调用了它,它将在数据库中插入很多次.我应该怎么做才能消除此冲突多次插入.
I have create a html string in json response which create a textbox and i have attached onkeypress function with it but my problem my onkeypress enter function called it will insert so many times in database .what should i do to remove this conflict for multiple insert.
推荐答案
对不起,以上解决方案被我删除,
请参考下面的一个:
你好,
使用以下代码:
私人void textBox1_KeyDown(object sender,KeyEventArgs e)
{
如果(e.KeyCode == Keys.Enter)
{
//按下Enter键(返回).
//...当用户按下此键时调用自定义方法.
AcceptMethod();
}
}
私有无效的AcceptMethod()
{
//在这里您可以编写用于在数据库中插入数据的操作;
}
希望对您有帮助,
快乐的编码.
sorry guys above solution deleted by me,
please refer below one:
hello,
use below code:
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
// Enter (return) was pressed.
// ... Call a custom method when user presses this key.
AcceptMethod();
}
}
private void AcceptMethod()
{
//here you can write your action for insert data in database;
}
hope this will help you,
happy coding..
这篇关于使用时如何触发功能在文本框上按Enter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文