Results 1 to 5 of 5

Thread: set focus

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    set focus

    How can I set focus to a txtbox in the page load handler?

  2. #2
    New Member
    Join Date
    Apr 2001
    Location
    Ghent, Belgium
    Posts
    5
    Yes it is possible , in several ways, but the most effective is:

    <FORM NAME="myFormName">
    <INPUT ITEM="text" NAME="myTextField">
    </FORM>
    <SCRIPT LANGUAGE=JAVASCRIPT><!--
    document.myFormName.myTextField.focus();
    //--></SCRIPT>

    It's client side script...

  3. #3

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    what if it's a web control instead of a HTML control?

  4. #4
    New Member
    Join Date
    Apr 2001
    Location
    Ghent, Belgium
    Posts
    5
    Sorry, send you the wrong code!
    This will work, except on self-made usercontrols...

    just add a 'imports system.text' line before your class dec.

    add this to your startup:

    Dim strBuilder As StringBuilder = New StringBuilder()

    strBuilder.Append("<script language='javascript'>")
    strBuilder.Append("function setFocus() {")
    strBuilder.Append("document.getElementById('TextBox3').focus();}")
    strBuilder.Append(" window.onload=setFocus;")
    strBuilder.Append("</script>")
    RegisterClientScriptBlock("Focus", strBuilder.ToString)


    Good luck!

    Tim.

  5. #5

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    thanks..

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