如何在asp.net中的textchanged事件上输入文本框时避免按钮单击事件 [英] how to avoid button click event when enter the textbox on textchanged event in asp .Net

查看:226
本文介绍了如何在asp.net中的textchanged事件上输入文本框时避免按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在textchanged事件上输入文本框时,按钮点击事件会自动触发。如何避免按钮点击事件按下文本框上的输入键。

when i enter the textbox on textchanged event the button click event automatically fire. how to avoid the button click event on press enter key on textbox.

推荐答案





你可以使用此方法检查是否按下了回车键。



Hi,

You can use this method to check whether enter key is pressed or not.

private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Return)
    {
        textBlock1.Text = "You Entered: " + textBox1.Text;
    }
}





或者您必须在onkeypress上以这种方式尝试客户端脚本。





or you have to try client side scripts in this way on onkeypress.

function (event) {
        if (event.which == 13 || event.keyCode == 13) {
            //code to execute here
            return false;
        }
        return true;
    });





根据您的需要实施。



祝你好运



Implement it according to your need.

Good Luck


这篇关于如何在asp.net中的textchanged事件上输入文本框时避免按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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