Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how do you set focus to next control on controls with autopostback so you don't have to hit tab twice?

Reply
Thread Tools

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

 
 
Mad Scientist Jr
Guest
Posts: n/a
 
      06-28-2004
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>")
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      06-29-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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>")



 
Reply With Quote
 
 
 
 
Mad Scientist Jr
Guest
Posts: n/a
 
      06-29-2004
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...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox keystroke Shorcut: Move focus to next tab - Does it exist ? Al Dykes Firefox 6 12-09-2007 12:11 AM
Could of field with autopostback - how to be able to set focus correctly. Mufasa ASP .Net 1 10-05-2007 03:29 AM
Can't hit the site by name but I can hit by IP CK ASP .Net 9 10-19-2006 08:01 PM
CurrentElement->next = CurrentElement->next->next (UNDEFINED?) Deniz Bahar C Programming 2 03-09-2005 12:45 AM
unable to set focus to control after validation (must tab twice to exit control) Mad Scientist Jr ASP .Net Web Controls 0 07-13-2004 08:01 PM



Advertisments