在ASP.NET文本框捕获键preSS [英] Catching keypress in ASP.NET textbox
问题描述
有一个简单waytØ捕获键preSS(在我的情况:F5)在ASP.NET文本框,并执行服务器的方法作为回应?
Is there an easy wayt o capture a keypress (in my case: F5) in a ASP.NET textbox, and executing a server method as a response?
我创建了一个简单的SQL前端,以及出于习惯(从SQL Server管理工作室),我把pressing F5时,我做了我的打字查询,但始终刷新,而不是执行浏览器,我的SQL查询: - )
I've created a simple SQL frontend, and out of habit (from SQL Server Mgmt Studio), I keep pressing F5 when I'm done typing my query, but that always refreshes the browser, instead of executing my SQL query :-)
我可以利用一些可能Javascript或做在ASP.NET jQuery的?
Can I do this in ASP.NET using possibly some Javascript or jQuery ?
马克
更新:
我有这样的jQuery的code我的ASP.NET页:
I have this jQuery code on my ASP.NET page:
$(document).ready(function() {
$("#<%= txtQuery.ClientID %>").keydown( function (e) {
if (e.keycode == 116) {
$("#<%= btnExecute.ClientID %>").trigger('click');
}
});
});
我试过e.which,e.key code的各种组合和关键code不同的值 - 但没有似乎工作。我在我的dev的机器上使用微软IE 7。 txtQuery
是我型我查询和ASP.NET文本框 btnExecute
是ASP.NET按钮,将发送要执行该查询到SQL Server。
I tried various combinations of "e.which", "e.keycode" and various values for keycode - but none seem to work. I'm using MS IE 7 on my dev machine. txtQuery
is the ASP.NET textbox where I type my query, and btnExecute
is the ASP.NET button which will send that query to SQL Server to be executed.
任何想法?我需要燮preSS标准的事件处理不知何故?如果是的话:那我怎么实现这个
Any ideas? Do I need to suppress the standard event handling somehow? And if so: then how do I accomplish that?
推荐答案
请参见键preSS(FN)
$("#yourtextboxId").keypress( function (e) {
// do stuff here
});
和
e.which
将确定重点pressed,我觉得关键code为F5为 116
有关触发事件可以使用
触发方法
$("#yourexecutescriptbutton").trigger('click');
编辑:
如果你需要捕捉F5然后给一个keydown事件处理程序
If you need to catch F5 then give a keydown event handler
$("#yourtextboxId").keydown( function (e) {
if ( e.which === 116 )
{
$("#yourexecutescriptbutton").trigger('click');
}
});
这篇关于在ASP.NET文本框捕获键preSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!