GeekIT1001
GeekIT1001

Reputation: 5

Execute function on specific key stroke in VB

I'm developing a web application that displays items from a work queue to a user. When an item is selected I have the app lock that item out so no other user can select it. By hitting the back button in the app it unlocks the item.

I want to be able to unlock the item if the user hits the backspace key. I know what code I need to unlock it. I just need to know how to make the code execute on backspace key stroke.

The code that I need to execute will be server side code.

Thanks in advance.

Upvotes: 0

Views: 366

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460138

  <script>
     document.onkeydown = function (e) 
     {
      if (window.event && window.event.keyCode == 8) { 
         __doPostBack('__Page', 'MyCustomArgument');
      }
     }
  </script>

If you need to execute code on server, you have to change your question accordingly

EDIT:

  • You could set a Hiddenfield's value to f.e. "unlockItem" and do a document.forms[0].submit() and checkthe hidden-value on serverside or better:
  • Use the clientside __doPostBack function generated from ASP.Net to submit page(for example on selectedIndexChanged of a DropDownList). You could even generate it from Codebehind if you want the cleanest way.

I changed the above code, but i think your next question could be how you should know which item was selected, won't it? Then you have to clarify what items we are talking about. On serverside you get the passed arguments with:

If Page.IsPostBack Then
    Dim eventArg As String = Request("__EVENTARGUMENT")
End If

End If

Upvotes: 2

Related Questions