How to put cursor in textbox onload

Discussion in 'ASP .Net' started by Asad, Apr 27, 2004.

  1. Asad

    Asad Guest

    I really really really need to put the cursor in a text box at onload.
    I can't figure out how to do this in ASP.NET. Anyone? In ASP.NET,
    javascript, anything ...
     
    Asad, Apr 27, 2004
    #1
    1. Advertisements

  2. Hi asadikhan,

    you can use the following sample script to do this, Replace the TextBox1
    with the name of the control to which you want to set the focus to

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    StringBuilder myJavaScript = new StringBuilder();

    myJavaScript.Append("<script language='Javascript'> function
    setfocus(){");
    myJavaScript.Append("document.getElementById(\"" +
    TextBox1.ClientID + "\").focus();");
    myJavaScript.Append("} setfocus();</script>");

    this.RegisterStartupScript("SetFocusScript",
    myJavaScript.ToString());
    }

    HTH
    Regards
    Ashish M Bhonkiya

    <> wrote in message
    news:...

    > I really really really need to put the cursor in a text box at onload.
    > I can't figure out how to do this in ASP.NET. Anyone? In ASP.NET,
    > javascript, anything ...
     
    Ashish M Bhonkiya, Apr 27, 2004
    #2
    1. Advertisements

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. Fabio R.
    Replies:
    0
    Views:
    1,018
    Fabio R.
    Mar 25, 2005
  2. =?Utf-8?B?VG9tYXMgS2VwaWM=?=

    Changing DEFAULT cursor to WAIT cursor in ASP

    =?Utf-8?B?VG9tYXMgS2VwaWM=?=, Apr 5, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,540
    Bruce Barker
    Apr 5, 2005
  3. dmaziuk
    Replies:
    3
    Views:
    932
    Chris Gonnerman
    Jan 25, 2011
  4. Geoff Davis
    Replies:
    3
    Views:
    318
    Geoff Davis
    Jan 15, 2004
  5. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    817
    Martin Honnen
    Nov 4, 2004
  6. Replies:
    5
    Views:
    480
    Thomas 'PointedEars' Lahn
    May 15, 2005
  7. Zvonko
    Replies:
    1
    Views:
    192
  8. marco

    onload -->* no onload

    marco, Jun 22, 2006, in forum: Javascript
    Replies:
    7
    Views:
    425
    marco
    Jun 24, 2006
Loading...