Results 1 to 3 of 3

Thread: Set focus to a textbox on page load

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    65

    Set focus to a textbox on page load

    I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page loads, I need the focus to be on one of the textboxes called txtUserName.

    I come from a VB background, so expecting the obvious, I go to the Page_Load event of the index.aspx page and try to write txtUserName.SetFocus but I see there isn't a SetFocus method for the System.Web.UI.WebControls.TextBox class.

    What's the way to set the focus to a textbox on the page load in ASP.NET?

  2. #2
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    Re: Set focus to a textbox on page load


  3. #3
    Junior Member
    Join Date
    Aug 2005
    Posts
    24

    Re: Set focus to a textbox on page load

    Hi , You may use a java script

    <SCRIPT LANGUAGE="JavaScript">
    function setFocus()
    {
    document.Form1('TxtCno').focus()
    }
    </SCRIPT>

    and call it in

    <body MS_POSITIONING="GridLayout" bgColor="#003366" onload="setFocus();">


    thats it it will focus the cursor on your desired field

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width