setting focus to a textbox

Discussion in 'ASP .Net' started by test test, Aug 30, 2003.

  1. test test

    test test Guest

    Hi,

    How can I set focus to a particular textbox on an aspx page in vb code? My
    problem is caused by the page updating when a user clicks a command button
    and I execute code (like updating a price when you click "Calculate" button,
    etc.). The button they click and the "Total" field is down toward the
    bottom of the web page and when the page updates, it resets to the top like
    you just opened the page.

    I have searched on the "Focus" method and my compile says:
    'focus' is not a member of 'System.Web.UI.Webcontrols.TextBox'.

    My code just reads: Textbox1.focus()

    Help.
     
    test test, Aug 30, 2003
    #1
    1. Advertising

  2. This has to be done on the client side using JavaScript. Example:

    document.forms[0].Textbox1.focus();

    NOTE: This uses the Name property of the text box. To use the ID, you would
    use:

    document.getElementById("Textbox1").focus();

    If you need to set the focus while handling a PostBack, just use
    Page.RegisterStartupScript() to insert the script in the page so that it
    executes on the client when the page loads.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    http://www.takempis.com
    Big Things are made up of
    Lots of Little Things.

    "test test" <> wrote in message
    news:k364b.46306$...
    > Hi,
    >
    > How can I set focus to a particular textbox on an aspx page in vb code?

    My
    > problem is caused by the page updating when a user clicks a command button
    > and I execute code (like updating a price when you click "Calculate"

    button,
    > etc.). The button they click and the "Total" field is down toward the
    > bottom of the web page and when the page updates, it resets to the top

    like
    > you just opened the page.
    >
    > I have searched on the "Focus" method and my compile says:
    > 'focus' is not a member of 'System.Web.UI.Webcontrols.TextBox'.
    >
    > My code just reads: Textbox1.focus()
    >
    > Help.
    >
    >
     
    Kevin Spencer, Aug 30, 2003
    #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. George Durzi

    Setting Focus on an asp:textbox

    George Durzi, Aug 20, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    617
    Marina
    Aug 20, 2003
  2. Brian Henry

    setting initial focus to textbox

    Brian Henry, Jul 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    543
    Craig Deelsnyder
    Jul 4, 2004
  3. Jason
    Replies:
    4
    Views:
    1,653
    Jason
    May 7, 2007
  4. Replies:
    2
    Views:
    348
    Thomas 'PointedEars' Lahn
    Jun 6, 2005
  5. Roger
    Replies:
    3
    Views:
    351
Loading...

Share This Page