简体   繁体   English

Asp.Net C#-在按键事件上执行存储的proc

[英]Asp.Net C# - Executing stored proc on keypress event

I know this sounds stupid. 我知道这听起来很愚蠢。 Also i know that this is hurting the server because of process every keypress event. 我也知道这会因为处理每个按键事件而伤害服务器。

But calling stored proc in keypress event is the only solution i've got so far to my problem. 但是到目前为止,我对问题的唯一解决方案是在按键事件中调用存储的proc。

but sometimes the result is not right when pressing too fast. 但有时按得太快时结果不正确。 This is because it always changes the value in textbox. 这是因为它总是更改文本框中的值。

Can anyone suggest me how to do it properly? 谁能建议我如何正确做? in javascript maybe or other option. 在javascript或其他选项中。

You may want to set a time out with javascript, for example 0.25 second before calling your stored proc. 您可能需要使用javascript设置超时时间,例如0.25秒,然后再调用存储的proc。

 <input type="text" onkeypress="myFunction()"> <script> var myVar; function myFunction() { clearTimeout(myVar); myVar = setTimeout(function(){ alert("Hello"); }, 2000); // 2 seconds } </script> 

In your case instead of alert("Hello") you want to call the SP 在您的情况下,您想调用SP而不是alert(“ Hello”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM