按ESC键的同时调用c#方法。 [英] Call a c# method while pressing the ESC key.

查看:217
本文介绍了按ESC键的同时调用c#方法。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在按下ESC键的同时调用c#方法。

但我的c#方法不是静态方法。

解决方案

进入你的页面(或者如果你的母版页有更多页面)你应该使用你的方法的JavaScript和AJAX调用,如下例所示:

< script type =text / javascript> 
函数的onkeydown(EVT){
如果(EVT =未定义&安培;!&安培; evt.keyCode == 27)// ESC
{

.ajax({
类型:POST,
url:/ Account / OnEscHandler//这里你应该改变你方法的URL!
});
}
};
window.document.onkeydown = onKeydown;
< / script>


I want to Call a c# method while pressing the ESC key.
But my c# method not a static method.

解决方案

Into your page (or if is for more pages into your master page) you should use JavaScript and AJAX call of your method like in the next example:

<script type="text/javascript">
function onKeydown(evt) {
            if (evt != undefined &&  evt.keyCode == 27) //Esc
            {


.ajax({ type: "POST", url: "/Account/OnEscHandler" //Here you should change the URL to your method! }); } }; window.document.onkeydown = onKeydown; </script>


这篇关于按ESC键的同时调用c#方法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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