Postback and Tab order

G

Guest

Hello,

I am doing web programming in VB ASP.NET. I have a group of fields that the
user can tab through in order and fill in info in each of the fields. Some
of the fields have code attached that runs when the value is changed in that
field. However, the problem is that when postback occurs to run this code,
it messes up the tab order for the user because, upon postsback, it starts
over and the first field in the list is where the tab starts again instead of
letting the user continue to continue tabbing down the list from where they
currently are. How can I get around this battle between postback and
taborder?

Thanks,
Dusty Hackney
 
S

S. Justin Gengo

Dusty,

Use a javascript to set focus on the field. A startup script such as this:

Private Sub SetFocus(ByVal webControl As
System.Web.UI.WebControls.WebControl)
If Not page.IsStartupScriptRegistered("ControlFocus") Then
Dim StringBuilder As New System.Text.StringBuilder
With StringBuilder
..Append("<script language=""javascript"">" & vbCrLf)
..Append(vbTab & "<!--" & vbCrLf)
..Append(vbTab & vbTab & "document.getElementById('" & webControl.ClientID &
"').focus();" & vbCrLf)
..Append(vbTab & "//-->" & vbCrLf)
..Append("</script>" & vbCrLf)
End With
page.RegisterStartupScript("ControlFocus", StringBuilder.ToString)
End If
End Sub

If you call this sub each time a control posts back and use it to set focus
on the next control you should be all set. Of course this only solves the
problem you're having if the client is running javascript, but most should
be.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
G

Guest

Thanks for the quick response.


S. Justin Gengo said:
Dusty,

Use a javascript to set focus on the field. A startup script such as this:

Private Sub SetFocus(ByVal webControl As
System.Web.UI.WebControls.WebControl)
If Not page.IsStartupScriptRegistered("ControlFocus") Then
Dim StringBuilder As New System.Text.StringBuilder
With StringBuilder
..Append("<script language=""javascript"">" & vbCrLf)
..Append(vbTab & "<!--" & vbCrLf)
..Append(vbTab & vbTab & "document.getElementById('" & webControl.ClientID &
"').focus();" & vbCrLf)
..Append(vbTab & "//-->" & vbCrLf)
..Append("</script>" & vbCrLf)
End With
page.RegisterStartupScript("ControlFocus", StringBuilder.ToString)
End If
End Sub

If you call this sub each time a control posts back and use it to set focus
on the next control you should be all set. Of course this only solves the
problem you're having if the client is running javascript, but most should
be.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

S. Justin Gengo [MCP]

Dusty,

You posted at the right time! :)

Did this take care of things for you?

--
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,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top