views:

47

answers:

1

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.

+2  A: 
  <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

Tim Schmelter
yep, it is working :). I tested keypress and had no result.
Danil
I'm glad I could help, don't forget to mark as answer when it is ;)
Tim Schmelter
Sorry I do need to execute code on server. Specifically I need to run a SQL update.
GeekIT1001
answer updated....
Tim Schmelter