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
  1. Home
  2. Web Development
  3. ASP.NET
  4. TextBox Focus

TextBox Focus

Scheduled Pinned Locked Moved ASP.NET
question
4 Posts 4 Posters 0 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.
  • O Offline
    O Offline
    oskardiazdeleon
    wrote on last edited by
    #1

    How do I set focus after a button is clicked to go directly into a textbox. Or even if its on load have the cursor right on the textbox automaticall Thanks

    M P S 3 Replies Last reply
    0
    • O oskardiazdeleon

      How do I set focus after a button is clicked to go directly into a textbox. Or even if its on load have the cursor right on the textbox automaticall Thanks

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      There are many ways to do that, for example in the button click's event handler you can call the Focus method of the textbox, see the sample code from here: http://msdn2.microsoft.com/en-us/library/ms178232.aspx[^]

      1 Reply Last reply
      0
      • O oskardiazdeleon

        How do I set focus after a button is clicked to go directly into a textbox. Or even if its on load have the cursor right on the textbox automaticall Thanks

        P Offline
        P Offline
        postmaster programmingknowledge com
        wrote on last edited by
        #3

        Create a module level function: Module Module1 Public Function SetFocus(ByVal FocusControl As Control) As String 'Setting focus to supplied control Dim Script As New System.Text.StringBuilder Dim ClientID As String = FocusControl.ClientID 'Building java script With Script .Append("") .Append("document.getElementById('") .Append(ClientID) .Append("').focus();") .Append("") End With Return Script.ToString() End Function End Module call the function above in button click event Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'set focus RegisterStartupScript("setFocus", Module1.SetFocus(TextBox1)) End Sub =postmaster http://www.programmingknowledge.com/[^]

        1 Reply Last reply
        0
        • O oskardiazdeleon

          How do I set focus after a button is clicked to go directly into a textbox. Or even if its on load have the cursor right on the textbox automaticall Thanks

          S Offline
          S Offline
          Suresh Pirsquare
          wrote on last edited by
          #4

          In the Page_Load Event, Type in:- Page.RegisterStartupScript("ss", "document.getElementById('" & TextBox1.ClientID & "').focus();") :) Thanks & regards, Suresh Dayma

          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