467,166 Members | 1,030 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,166 developers. It's quick & easy.

how do you set focus to next control on controls with autopostback so you don't have to hit tab twice?

I have autopostback turned on for Textbox1. When the user tabs out of
it, the codebehind recalculates some other fields based on its value,
and the user should be able to start typing a value in the next
control Textbox2. However, when the page is rendered, the focus goes
back to Textbox1. In order to go to the next control the user has to
hit tab twice - once to recalculate, and once to tab out of the
control. Is there some way to make it so that a single tab
recalculates AND brings the user to the next control?

I have tried putting in the following javascript to do it after
recalculation, but it doesn't seem to work:

(DO RECALCULATIONS HERE)
....

' SET FOCUS ON NEXT CONTROL
'Page.RegisterClientScriptBlock("SetFocus", "<script
language='javascript'>document.form.Texboxt2.focus ();</script>")
Nov 18 '05 #1
  • viewed: 2151
Share:
2 Replies
the javascript (which will render after the form and before any controls) is
runnig before the control is rendered. execute on form load.

Page.RegisterClientScriptBlock("SetFocus", @"<script> language='javascript'>
document.body.onload = function(){ document.form.Texboxt2.focus();}
</script>");
-- bruce (sqlwork.com)
"Mad Scientist Jr" <us*************@yahoo.com> wrote in message
news:7a**************************@posting.google.c om...
I have autopostback turned on for Textbox1. When the user tabs out of
it, the codebehind recalculates some other fields based on its value,
and the user should be able to start typing a value in the next
control Textbox2. However, when the page is rendered, the focus goes
back to Textbox1. In order to go to the next control the user has to
hit tab twice - once to recalculate, and once to tab out of the
control. Is there some way to make it so that a single tab
recalculates AND brings the user to the next control?

I have tried putting in the following javascript to do it after
recalculation, but it doesn't seem to work:

(DO RECALCULATIONS HERE)
...

' SET FOCUS ON NEXT CONTROL
'Page.RegisterClientScriptBlock("SetFocus", "<script
language='javascript'>document.form.Texboxt2.focus ();</script>")

Nov 18 '05 #2
I tried it, but the focus still stayed on the control that had the
AutoPostback and I had to hit tab again to go to the next control.
Thanks anyway...
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by tshad | last post: by
4 posts views Thread by Christian Ista | last post: by
1 post views Thread by robin9876@hotmail.com | last post: by
4 posts views Thread by Jon Slaughter | last post: by
1 post views Thread by RN1 | last post: by
8 posts views Thread by Mel | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.