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

M

Mad Scientist Jr

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>")
 
B

bruce barker

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)
 
M

Mad Scientist Jr

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...
 

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

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,809
Latest member
moe77

Latest Threads

Top