How to Have RETURN on textbox activate submit button?

Last post 08-17-2005 5:03 AM by aspci. 8 replies.

Sort Posts:

  • How to Have RETURN on textbox activate submit button?

    08-15-2005, 1:10 PM
    • Participant
      1,713 point Participant
    • Fonzie
    • Member since 06-10-2005, 2:10 PM
    • Posts 823
    Right now, after I type some text in the textbox, hitting enter does not move the focus to the command button nor does it activate it. Instead, I have to use the mouse and click on command button to activate it/submit the query. Is there a way around this?
  • Re: How to Have RETURN on textbox activate submit button?

    08-15-2005, 1:16 PM
    • All-Star
      46,027 point All-Star
    • joteke
    • Member since 06-16-2002, 3:24 PM
    • Kyro, Finland
    • Posts 6,879
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs
  • Re: How to Have RETURN on textbox activate submit button?

    08-15-2005, 1:18 PM
    • All-Star
      119,435 point All-Star
    • XIII
    • Member since 06-30-2002, 11:59 PM
    • Essen, Belgium
    • Posts 13,292
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs
  • Re: How to Have RETURN on textbox activate submit button?

    08-15-2005, 4:06 PM
    • Participant
      1,713 point Participant
    • Fonzie
    • Member since 06-10-2005, 2:10 PM
    • Posts 823
    I attempted this one becasue it looked the simplest:
    http://www.hanselman.com/blog/ASPNETHowToCreateADefaultEnterButtonForFormsPostBacks.aspx

    my form didn't have a load event(that I could see) so I add the following per the above link but to no effect.

    Sub Page_Load
    Page.RegisterHiddenField("__EVENTTARGET", "Button1")
    End Sub

    Also, is there a way for the form's only textbox to have the focus when the form loads?
  • Re: How to Have RETURN on textbox activate submit button?

    08-16-2005, 4:24 PM
    • All-Star
      119,435 point All-Star
    • XIII
    • Member since 06-30-2002, 11:59 PM
    • Essen, Belgium
    • Posts 13,292
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs
     Fonzie wrote:
    Also, is there a way for the form's only textbox to have the focus when the form loads?


    You might want to take a look at this free control: FirstFocus.

    Grz, Kris.
  • Re: How to Have RETURN on textbox activate submit button?

    08-16-2005, 4:31 PM
    • Participant
      1,713 point Participant
    • Fonzie
    • Member since 06-10-2005, 2:10 PM
    • Posts 823
    that looks like java script. I am trying to learn VB, would this confuse the issue?
  • Re: How to Have RETURN on textbox activate submit button?

    08-16-2005, 5:02 PM
    • Star
      9,642 point Star
    • uncleb
    • Member since 07-30-2002, 4:18 PM
    • Posts 1,863
    Although you are programming ASP.Net using the VB language - that is only the server-side.We control what the server does using .Net framework
    JavaScript is used for client-side programming, meaning the "browser" does the work
    Setting the focus is a client-side action- hence you need to use JavaScript

    Learning the differences between what is server-side and client-side is an important concept in WEB development

    I will take some time - but just ask yourself- does browser do this?(if yes - then it's client-side) or does the server? (server-side via Framework)

    HTH
    Hope That Helps
    All that wander, are not lost...
    What were we talkin bout
  • Re: How to Have RETURN on textbox activate submit button?

    08-17-2005, 1:13 AM
    • All-Star
      119,435 point All-Star
    • XIII
    • Member since 06-30-2002, 11:59 PM
    • Essen, Belgium
    • Posts 13,292
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs
     Fonzie wrote:
    that looks like java script. I am trying to learn VB, would this confuse the issue?

    Javascript is executed on the client side and ASP.NET (doesn't matter if you use C# or VB.NET) is executed on the server side. You can find interesting learning courses for a bunch of "web" languages (html, css, asp.net, javascript, ...) here: w3schools.

    If you have questions about javascript I would suggest that you take a look or ask your questions on the "client side web development" forum.

    Grz, Kris.
  • Re: How to Have RETURN on textbox activate submit button?

    08-17-2005, 5:03 AM
    • Member
      237 point Member
    • aspci
    • Member since 07-13-2005, 8:17 AM
    • Posts 48
    i think there one textbox in your page. if so, u must put another textbox on your page and set its visibility to hidden with style.

    <asp:TextBox id="txtInv" runat="server" Width="10px" style="display:none;visiblity:hidden">

    submit button will run when u hit the enter in your textbox....
Page 1 of 1 (9 items)