How to programatically set focus onto a web control ?

Discussion in 'ASP .Net Web Controls' started by news.iq.ca, Nov 26, 2004.

  1. news.iq.ca

    news.iq.ca Guest

    Hi,

    I have a form containing a number of panels, simulating a wizard
    (simulating, actually, a multi-page form). After pressing a button called
    "Next", I am showing a new panel on this form, loaded with some controls. I
    need to set the focus onto a textbox in the newly shown panel right away,
    without "asking" the user to tab (or to click) his way towards my textbox.
    So please, how can I set the focus programatically on any control on my form
    ?

    Maybe using "FindControl" ?? And then ?

    Thank you
    Alex
     
    news.iq.ca, Nov 26, 2004
    #1
    1. Advertising

  2. news.iq.ca

    David Jessee Guest

    in the button's handler, put something like...
    me.RegisterClientStartupScript("initialFocus","<script
    language=javascript>document.Form1.theControlYouWant.focus();</script>")

    be careful. If your text box us called text1 and its inside panel1 then the
    clientID might be something like panel1:text1

    You'll want to either do a View>>Source on your HTML to see what the client
    ID is, or use the Test Box's ClientID property

    "news.iq.ca" <> wrote in message
    news:41a6dde4_2@aeinews....
    > Hi,
    >
    > I have a form containing a number of panels, simulating a wizard
    > (simulating, actually, a multi-page form). After pressing a button called
    > "Next", I am showing a new panel on this form, loaded with some controls.

    I
    > need to set the focus onto a textbox in the newly shown panel right away,
    > without "asking" the user to tab (or to click) his way towards my textbox.
    > So please, how can I set the focus programatically on any control on my

    form
    > ?
    >
    > Maybe using "FindControl" ?? And then ?
    >
    > Thank you
    > Alex
    >
    >
     
    David Jessee, Nov 26, 2004
    #2
    1. Advertising

  3. Hi Alex,

    You might want to investigate this free control:

    FirstFocus Control
    This control creates the proper javascript to give focus to control after
    the page has loaded.

    http://www.metabuilders.com/Tools/FirstFocus.aspx

    "news.iq.ca" <> wrote in message
    news:41a6dde4_2@aeinews....
    > Hi,
    >
    > I have a form containing a number of panels, simulating a wizard
    > (simulating, actually, a multi-page form). After pressing a button called
    > "Next", I am showing a new panel on this form, loaded with some controls.
    > I need to set the focus onto a textbox in the newly shown panel right
    > away, without "asking" the user to tab (or to click) his way towards my
    > textbox. So please, how can I set the focus programatically on any control
    > on my form ?
    >
    > Maybe using "FindControl" ?? And then ?
    >
    > Thank you
    > Alex
    >
     
    Ken Cox [Microsoft MVP], Nov 26, 2004
    #3
  4. news.iq.ca

    news.iq.ca Guest

    Thanks a lot for your answers. :)))

    Alex.

    "news.iq.ca" <> wrote in message
    news:41a6dde4_2@aeinews....
    > Hi,
    >
    > I have a form containing a number of panels, simulating a wizard
    > (simulating, actually, a multi-page form). After pressing a button called
    > "Next", I am showing a new panel on this form, loaded with some controls.
    > I need to set the focus onto a textbox in the newly shown panel right
    > away, without "asking" the user to tab (or to click) his way towards my
    > textbox. So please, how can I set the focus programatically on any control
    > on my form ?
    >
    > Maybe using "FindControl" ?? And then ?
    >
    > Thank you
    > Alex
    >
     
    news.iq.ca, Dec 2, 2004
    #4
  5. news.iq.ca

    Ryan De Laet Guest

    Try here:
    http://lucaslabs.net/blogs/mccullochs/archive/2004/07/23/875.aspx

    "news.iq.ca" <> wrote in message
    news:41aea2ec_4@aeinews....
    > Thanks a lot for your answers. :)))
    >
    > Alex.
    >
    > "news.iq.ca" <> wrote in message
    > news:41a6dde4_2@aeinews....
    > > Hi,
    > >
    > > I have a form containing a number of panels, simulating a wizard
    > > (simulating, actually, a multi-page form). After pressing a button

    called
    > > "Next", I am showing a new panel on this form, loaded with some

    controls.
    > > I need to set the focus onto a textbox in the newly shown panel right
    > > away, without "asking" the user to tab (or to click) his way towards my
    > > textbox. So please, how can I set the focus programatically on any

    control
    > > on my form ?
    > >
    > > Maybe using "FindControl" ?? And then ?
    > >
    > > Thank you
    > > Alex
    > >

    >
    >
     
    Ryan De Laet, Dec 16, 2004
    #5
    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. Milsnips
    Replies:
    0
    Views:
    396
    Milsnips
    Nov 16, 2005
  2. SpencerW
    Replies:
    5
    Views:
    255
    Steven Cheng[MSFT]
    May 27, 2005
  3. Brian Edwards

    Can't drag Web Custom Control from Toolbox onto Webform

    Brian Edwards, Nov 14, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    176
    Brian Edwards
    Nov 14, 2005
  4. Replies:
    2
    Views:
    346
    Thomas 'PointedEars' Lahn
    Jun 6, 2005
  5. Roger
    Replies:
    3
    Views:
    345
Loading...

Share This Page