且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

按ESC键的同时调用c#方法。

更新时间:2023-10-21 23:38:52

进入你的页面(或者如果你的母版页有更多页面)你应该使用你的方法的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>