Search code examples
c#asp.netstored-procedureskeypress

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.

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.


Solution

  • You may want to set a time out with javascript, for example 0.25 second before calling your stored 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