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. focus

focus

Scheduled Pinned Locked Moved ASP.NET
comquestion
6 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.
  • V Offline
    V Offline
    V 0
    wrote on last edited by
    #1

    Hi, I want to set the focus to a textbox when loading the first page (guess what, it's a logon form :-D), just like mail.yahoo.com How do you do that? tnx. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

    K S A 3 Replies Last reply
    0
    • V V 0

      Hi, I want to set the focus to a textbox when loading the first page (guess what, it's a logon form :-D), just like mail.yahoo.com How do you do that? tnx. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

      K Offline
      K Offline
      khurram rathor
      wrote on last edited by
      #2

      Hello, You can do it through JavaScript. Use "onload" event for a body tag and do focus in that event. Like.. < script language="javascript"> function StartFocuse() { document.Logon.txtName.focus(); } < /script> and declare event in the body Tag like.. < body MS_POSITIONING="GridLayout" onload="StartFocuse()"> < form id="Logon" method="post" runat="server"> ...... ...... < /form> < /body> khurram rathor

      V 1 Reply Last reply
      0
      • V V 0

        Hi, I want to set the focus to a textbox when loading the first page (guess what, it's a logon form :-D), just like mail.yahoo.com How do you do that? tnx. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

        S Offline
        S Offline
        Stefan Troschuetz
        wrote on last edited by
        #3

        To avoid the usage of javascript, try using tabindexes for your controls. The one with the lowest index should get focus.


        www.troschuetz.de

        V 1 Reply Last reply
        0
        • S Stefan Troschuetz

          To avoid the usage of javascript, try using tabindexes for your controls. The one with the lowest index should get focus.


          www.troschuetz.de

          V Offline
          V Offline
          V 0
          wrote on last edited by
          #4

          tnx for you reply, but unfortunately I've been there and done that. (and Z-Index too) tnx for the effort though. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

          1 Reply Last reply
          0
          • V V 0

            Hi, I want to set the focus to a textbox when loading the first page (guess what, it's a logon form :-D), just like mail.yahoo.com How do you do that? tnx. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

            A Offline
            A Offline
            asifmaniar
            wrote on last edited by
            #5

            try this method: so on page load call SetInitialFocus(TextBox_Name) public void SetInitialFocus(Control ctrl) { StringBuilder s = new StringBuilder() ; s.Append("") ; s.Append("function SetInitialFocus()") ; s.Append("{") ; s.Append(" document.") ; Control p = new Control(); p= ctrl.Parent ; while (! (p is System.Web.UI.HtmlControls.HtmlForm )) p = p.Parent ; s.Append(p.ClientID) ; s.Append("['") ; s.Append(ctrl.UniqueID) ; s.Append("'].focus();") ; s.Append("}") ; s.Append("window.onload = SetInitialFocus;") ; s.Append("") ; ctrl.Page.RegisterClientScriptBlock("InitialFocus", s.ToString()) ; }

            1 Reply Last reply
            0
            • K khurram rathor

              Hello, You can do it through JavaScript. Use "onload" event for a body tag and do focus in that event. Like.. < script language="javascript"> function StartFocuse() { document.Logon.txtName.focus(); } < /script> and declare event in the body Tag like.. < body MS_POSITIONING="GridLayout" onload="StartFocuse()"> < form id="Logon" method="post" runat="server"> ...... ...... < /form> < /body> khurram rathor

              V Offline
              V Offline
              V 0
              wrote on last edited by
              #6

              Yes idd, it worked like a charm. tnx :-) "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

              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