locked
How to use ENTER key to submit/postback web part? RRS feed

  • Question

  • Is there any way to use ENTER key to submit webform in web part?It is really annoying to click mouse button rather than hit enter key directly when you try to submit a web form.

    Thursday, January 27, 2011 5:40 AM

Answers

  • Hi Commandolee,

    This may help, it is from this website: http://www.beansoftware.com/ASP.NET-Tutorials/Accept-Enter-Key.aspx

    "ASP.NET 2.0 makes this problems easier and introduce a concept of a "default button". New defaultbutton attribute can be used with <form> or <asp:panel> control. What button will be "clicked" depends of where actually cursor is and what button is chosen as a default button for form or a panel.

    Here is sample HTML code that contains one form and one panel control:"

    <form defaultbutton="button1" runat="server">
      <asp:textbox id="textbox1" runat="server"/>
      <asp:textbox id="textbox2" runat="server"/>
      <asp:button id="button1" text="Button1" runat="server"/>
      <asp:panel defaultbutton="button2" runat="server">
        <asp:textbox id="textbox3" runat="server"/>
        <asp:button id="button2" runat="server"/>
      </asp:panel>
    </form> 
    

    Regards

    Phill


    Lightning Tools – The Company where I work.

    BCS Tester Man the BCS Test Client – My Personal Project on CodePlex

    • Proposed as answer by Jonathan Mast Saturday, January 29, 2011 5:55 PM
    • Marked as answer by Commandolee Monday, January 31, 2011 1:18 AM
    Friday, January 28, 2011 9:58 AM

All replies

  • Hi Commandolee,

    This may help, it is from this website: http://www.beansoftware.com/ASP.NET-Tutorials/Accept-Enter-Key.aspx

    "ASP.NET 2.0 makes this problems easier and introduce a concept of a "default button". New defaultbutton attribute can be used with <form> or <asp:panel> control. What button will be "clicked" depends of where actually cursor is and what button is chosen as a default button for form or a panel.

    Here is sample HTML code that contains one form and one panel control:"

    <form defaultbutton="button1" runat="server">
      <asp:textbox id="textbox1" runat="server"/>
      <asp:textbox id="textbox2" runat="server"/>
      <asp:button id="button1" text="Button1" runat="server"/>
      <asp:panel defaultbutton="button2" runat="server">
        <asp:textbox id="textbox3" runat="server"/>
        <asp:button id="button2" runat="server"/>
      </asp:panel>
    </form> 
    

    Regards

    Phill


    Lightning Tools – The Company where I work.

    BCS Tester Man the BCS Test Client – My Personal Project on CodePlex

    • Proposed as answer by Jonathan Mast Saturday, January 29, 2011 5:55 PM
    • Marked as answer by Commandolee Monday, January 31, 2011 1:18 AM
    Friday, January 28, 2011 9:58 AM
  • Hi Phill,

    You are the hero! Thanks!

    Monday, January 31, 2011 1:18 AM