Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
3.40/5 (5 votes)
See more:
I want disable tab key in a asp.net form
Posted
Updated 28-Jul-16 23:17pm
Comments
Sergey Alexandrovich Kryukov 23-Oct-12 15:56pm    
Why would you do it, ever?
--SA
Sergey Alexandrovich Kryukov 24-Oct-12 10:28am    
Excuse me please: I have an impression that there were several answers and comments on this page. Is that so? Do you have any idea why they are gone?
--SA
me64 24-Oct-12 11:31am    
Yes, I'm quitting this job. But if there is a way, I want to know

You can capture the tab key press with a code snippet similar to what I give you below, but this solution will NOT work in IE.
The crappy thing is that you'll have to attach this handler to every control on your form that can receive focus.

I must strongly recommend that you do NOT do this. The tab-key functionality is what it is for a reason and is a default behavior that is very consistent across browsers. People expect the tab key to move them between elements in a web form, so why confuse them?

JavaScript
$('#textbox').live('keydown', function(e) {
  var keyCode = e.keyCode || e.which;

  if (keyCode == 9) {
    e.preventDefault();
    // call custom function here
  }
});
 
Share this answer
 
Comments
me64 23-Oct-12 12:41pm    
what is "call custom function here", which function?
fjdiewornncalwe 23-Oct-12 12:57pm    
That just means that you enter your code or a call to what you want done... It really doesn't mean much of anything.
Akinmade Bond 23-Oct-12 14:01pm    
Seriously?
fjdiewornncalwe 23-Oct-12 14:06pm    
LOL... I actually thought you were responding to my comment at first glance. Cheers.
Akinmade Bond 23-Oct-12 14:08pm    
No! Gave ya a five. :)
No, you don't want to do it, why? This is such an abuse that, should I ever visited such page, I would be much troubled, and, when found that it wasn't a browser glitch, would place your site to my "never visit" list. If you already have or develop some site, please give me a reference, for this purpose. :-)

—SA
 
Share this answer
 
How about:

HTML
$('#textbox').live('keydown', function(e) 
{
  var keyCode = e.keyCode || e.which;
 
  if (keyCode == Keys.Tab) 
  {
     e.Handled = true;
  }
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900