How to set focus to a particular control in .net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhappy
    New Member
    • Jul 2007
    • 139

    How to set focus to a particular control in .net

    Hai all,

    Im having one image with link(www.google .com) on top of the page, bellow that one textbox and one button(search) is there.If i type text in textbox and if i press "enter" then that link is opening,how to set focus to search button...?

    thanks,
    Aswath.
  • dip_developer
    Recognized Expert Contributor
    • Aug 2006
    • 648

    #2
    Originally posted by bhappy
    Hai all,

    Im having one image with link(www.google .com) on top of the page, bellow that one textbox and one button(search) is there.If i type text in textbox and if i press "enter" then that link is opening,how to set focus to search button...?

    thanks,
    Aswath.
    see here........
    how to set focus on a control by javascript

    Comment

    • todashah
      New Member
      • Feb 2008
      • 26

      #3
      In Case of if u r using c# then write down following code in the
      key down event of text box.

      if(e.KeyCode==K eys.Enter)
      button1.Focus() ;

      or

      if u want that once u type something in text box & press enter key & its
      invoke button then set acceptbutton property of form to name of button
      in case of only one button is there on form.

      Comment

      • kunal pawar
        Contributor
        • Oct 2007
        • 297

        #4
        u can give form as defaultbutton as hyperlink. so whn user press "Enter" that button will press.

        Comment

        • bhappy
          New Member
          • Jul 2007
          • 139

          #5
          Hai
          Thanks for replay,
          Im using vb.net, where i didn't get any event like keydown for textbox

          And i didn't got what is form defaultbutton as hyperlink? where should i apply this..??

          thanks,
          Aswath.

          Comment

          • bhappy
            New Member
            • Jul 2007
            • 139

            #6
            Hia all,

            Defaultbutton property is working in asp.net2.0 only but im using asp.net1.1
            and i tried this method
            txtsrh.Attribut es.Add("onKeyPr ess", "javascript :if (event.keyCode == 13) __doPostBack('" + ImageButton1.Un iqueID + "','')retur n false;")

            but it is not happening

            Comment

            • kunal pawar
              Contributor
              • Oct 2007
              • 297

              #7
              may be it works
              say return true at last not false;

              Comment

              Working...