Tab order & postback confusion

J

John Wilson

I am sure there is an easy answer to this, so here goes...

Imagine a web form consists of two text boxes and some labels. The textboxes
are given a tab order of 1 & 2, and each posts back to the server
ontextchanged. What actually happens in practice is this:

I change text in textbox1.
I press tab to go on to textbox 2.
Focus (ie blinking cursor) moves to textbox2.
Form then blinks (presumably as trip to server is made as per
textbox1.ontextchanged).
Textbox2 then loses focus (in fact nothing seems to have focus).

It seems to me that the trip back to the server is defeating the object of
having a tab order. How do I get the form to come back from the server with
focus still where it should be (ie in textbox2 in this example)?

Thanks a lot.
 
S

S. Justin Gengo

John,

Yes, the postback is defeating tab order in this instance. Each post back
the page is brand new so you get tab 1.

The way to handle this is in the text box's on text changed event. You can
use a javascript to set the focus to the next control.

E.g. in the first textbox's on text changed:

Page.RegisterStartupScript("TextBoxFocus", "<script
language=""javascript"">document.getElementById('" & TextBox2.ClientId &
"').focus();</script>")

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top