javascript 按回车键触发 ASP.NET TextBox 事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4254576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fire an ASP.NET TextBox event on enter press
提问by Kimtho6
How do i fire a ASP.NET click event when the user press enter.
当用户按下 Enter 键时,我如何触发 ASP.NET 单击事件。
This is what i do now but it does not work:
这就是我现在所做的,但它不起作用:
function KeyDownHandler(event) {
if (event.keyCode == 13) {
__doPostBack('<% ButtonGetListforUser.ClientID %>', 'OnClick');
isClicked = true;
}
}
回答by Oleg Kalenchuk
Try to use the Panel.DefaultButton Property
回答by Kimtho6
i used this exsample to make it work Panel.DefaultButton Property Exsample
我使用此示例使其工作 Panel.DefaultButton 属性示例
回答by rbhro
$(document).ready(function(){
$(window).keydown(function(e){
if(e.keyCode == 13) $('#<% ButtonGetListforUser.ClientID %>'.click();
});
});
回答by Salih
This answer for C# ASPNET
Control name : Textbox1
C# ASPNET
控件名称的这个答案:Textbox1
Add TextChanged eventfor the textbox then add your code in this block as below.
protected void Textbox1_TextChanged(object sender, EventArgs e) { // Add your code here }Add below block to add Enter event to textbox
private void Textbox1_Enter(object sender, System.EventArgs e) { Textbox1_TextChanged((object)sender, (EventArgs)e); }
为文本框添加 TextChanged 事件,然后在此块中添加您的代码,如下所示。
protected void Textbox1_TextChanged(object sender, EventArgs e) { // Add your code here }添加以下块以将 Enter 事件添加到文本框
private void Textbox1_Enter(object sender, System.EventArgs e) { Textbox1_TextChanged((object)sender, (EventArgs)e); }

