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

  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
     
    David Jessee, Nov 26, 2004
    #2
    1. Advertisements

  3. 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, Dec 2, 2004
    #4
  5. news.iq.ca

    Ryan De Laet Guest

    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.