Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Textbox focus

Textbox focus

Scheduled Pinned Locked Moved ASP.NET
question
4 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dylan van Heerden
    wrote on last edited by
    #1

    Hi everyone How would I set focus to a textbox control on page load?

    A T 2 Replies Last reply
    0
    • D Dylan van Heerden

      Hi everyone How would I set focus to a textbox control on page load?

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      use this below code to set focus to any control call this function in form load as SetFocus(TextBox1) Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control) Dim s As String = "document.getElementById('" & ctrl.ID & "').focus() " RegisterStartupScript("focus", s) End Sub

      D 1 Reply Last reply
      0
      • A Anonymous

        use this below code to set focus to any control call this function in form load as SetFocus(TextBox1) Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control) Dim s As String = "document.getElementById('" & ctrl.ID & "').focus() " RegisterStartupScript("focus", s) End Sub

        D Offline
        D Offline
        Dylan van Heerden
        wrote on last edited by
        #3

        Thanks a lot man....

        1 Reply Last reply
        0
        • D Dylan van Heerden

          Hi everyone How would I set focus to a textbox control on page load?

          T Offline
          T Offline
          tojamismis
          wrote on last edited by
          #4

          It requires a javascript function. if you want to set the cursor to a textbox named "Mytext" In Page_Load add the following lines: string strJS = "function SetFocus(ControlName)" + "{document.getElementByID('" + Mytext.ClientID + "').focus();}"; Page.RegisterStartupScript("SetFocus", strJS); Tojamismis
          'In the immortal words of Socrates - "I drank what?".'

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups