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. focusing textbox at runtime

focusing textbox at runtime

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-netquestion
3 Posts 3 Posters 1 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.
  • M Offline
    M Offline
    Member 1228843
    wrote on last edited by
    #1

    how can i focus a textbox at runtime in asp.net without using javascript

    B 1 Reply Last reply
    0
    • M Member 1228843

      how can i focus a textbox at runtime in asp.net without using javascript

      B Offline
      B Offline
      Britnt7
      wrote on last edited by
      #2

      What is the reason why you don't want to use javascript? For me it worked great. The code is written in VB.Net.

      Private Sub FocusOnControl(ByVal Name As String)
      Dim strBuilder As String = ""
      strBuilder += ""
      strBuilder += "document.getElementById('" + Name + "').focus();"
      strBuilder += ""
      RegisterStartupScript("FocusOnControl", strBuilder)
      End Sub

      Then in the page load event call the FocusOnControl function:

      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      If Not Page.IsPostBack Then
      FocusOnControl("name of textbox")
      End If
      End Sub

      You can use the FocusOnControl("name of textbox") anywhere in your code and use any textbox you wish. I jump from textbox to textbox.\ Hope this helps.;)

      Z 1 Reply Last reply
      0
      • B Britnt7

        What is the reason why you don't want to use javascript? For me it worked great. The code is written in VB.Net.

        Private Sub FocusOnControl(ByVal Name As String)
        Dim strBuilder As String = ""
        strBuilder += ""
        strBuilder += "document.getElementById('" + Name + "').focus();"
        strBuilder += ""
        RegisterStartupScript("FocusOnControl", strBuilder)
        End Sub

        Then in the page load event call the FocusOnControl function:

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
        FocusOnControl("name of textbox")
        End If
        End Sub

        You can use the FocusOnControl("name of textbox") anywhere in your code and use any textbox you wish. I jump from textbox to textbox.\ Hope this helps.;)

        Z Offline
        Z Offline
        zzq9624
        wrote on last edited by
        #3

        You can use javascript . document.form1.nameoftextbox.focus i love dotnet !

        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