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

Discussion in 'ASP .Net' started by Mad Scientist Jr, Jun 28, 2004.

  1. 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>")
     
    Mad Scientist Jr, Jun 28, 2004
    #1
    1. Advertising

  2. Mad Scientist Jr

    bruce barker Guest

    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" <> wrote in message
    news:...
    > 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>")
     
    bruce barker, Jun 29, 2004
    #2
    1. Advertising

  3. 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...
     
    Mad Scientist Jr, Jun 29, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CK
    Replies:
    9
    Views:
    410
    Jerry Rasmussen
    Oct 19, 2006
  2. Deniz Bahar
    Replies:
    2
    Views:
    496
    Andrey Tarasevich
    Mar 9, 2005
  3. Mufasa
    Replies:
    1
    Views:
    408
    Elroyskimms
    Oct 5, 2007
  4. Mad Scientist Jr
    Replies:
    0
    Views:
    393
    Mad Scientist Jr
    Jul 13, 2004
  5. Roger
    Replies:
    3
    Views:
    351
Loading...

Share This Page