Click here to Skip to main content
16,011,804 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on an ASP.NET 2.0 (VB) web application. I am having trouble controlling tab behavior.

TabIndex is set throughout the form and tabs as expected.

But,after making a change in a textbox and hitting Tab or Enter, the focus jumps to the web address bar instead of the next field.

I have tried:
1.SetFocus on the text change event
2.Saving last field name in a hidden textbox and set focus to saved textbox name on Page Load if Post back
3.SetFocus on Pre_render

Still, focus jumps to browser address bar on tab or enter.

I think it may be losing the tab index on post-back.

Any clues?

Thanks in advance, any help is appreciated
Posted

Found this:

Shift Focus to the Next Control during a PostBack using ASP.NET and LINQ
http://www.dotnetcurry.com/ShowArticle.aspx?ID=253[^]

It was exactly what I needed!
 
Share this answer
 
Hi,

Tab order can be controled with tabindex property on some html tags. Look thi example:
HTML
<html>
<head>
  <title>TAB Order test</title>
</head>
<body>
  <form>
    Text1 (first tab):
    <input type="text" name="txt1" tabindex=1 /><br />
    Text2 (third tab):
    <input type="text" name="txt2" tabindex=3 /><br />
    Text3 (fourth tab):
    <input type="text" name="txt3" tabindex=4 /><br />
    Text4 (second tab):
    <input type="text" name="txt4" tabindex=2 /><br />
  </form>
</body>
</html></html>

Suported tags are a, textarea, select and input types...
If you want to skip control then set its tabindex to 0 (tabindex=0).

One more link that can be useful. Look control your tab order and cursor focus [^]. ;)
 
Share this answer
 
v3
The browser address bar is not part of your HTML. As such, it's not possible to write code that sets the focus from the page to the bar. I would in general try to move to AJAX if I could, and I would try to put some javascript in the page so that on page load, it sets the focus you want, instead of trusting the code behind to do it for you.
 
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