Trap Enter Key

ChuckMac

Member
Joined
Jun 27, 2007
Messages
6
Programming Experience
10+
I have seen a couple of ways to capture or Trap the Enter Key in Windows Forms, is there a way to trap the <Enter> in Web forms and SendKey <Tab>?
 
You have to work client-side with Javascript, Enter key can be detected and redirected to Tab with this function:
VB.NET:
function entertab() {
    if (event.keyCode==13) {event.keyCode=9; return event.keyCode }
}
An element need onkeydown attribute set to value "javascript:entertab()". For server controls this can be added with this code-behind:
VB.NET:
TextBox1.Attributes.Add("onkeydown", "javascript:entertab()")
You'll find loads of workarounds for your inquiry if you search web "javascript enter tab", this also includes many different ways of calling focus() method of next element when Enter is detected.
 
Thanks Tom,

I'll try this after dinner.
Could you tell me where to put the:
TextBox1.Attributes.Add("onkeydown", "javascript:entertab()")
Code so it gets registered in the class..

Thanks.. Chuck..
 
In the code-behind, the server code, page Load event should suit it.
 
Back
Top