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

  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. 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. Fabio R.
    Replies:
    0
    Views:
    834
    Fabio R.
    Mar 25, 2005
  2. dmaziuk
    Replies:
    3
    Views:
    611
    Chris Gonnerman
    Jan 25, 2011
  3. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    599
    Martin Honnen
    Nov 4, 2004
  4. Replies:
    5
    Views:
    297
    Thomas 'PointedEars' Lahn
    May 15, 2005
  5. marco

    onload -->* no onload

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

Share This Page