2012-05-29

Fire a button event when press the Enter key

Use asp:Panel to enclose all the controls and define a DefaultButton (The button ID you want to fire when the user press 'Enter' key.)

<asp:Panel runat="server" DefaultButton="btn2">
    <asp:TextBox ID="1" runat="server"></asp:TextBox>
    <asp:Button ID="btn1" runat="server"  OnClick="btn1_Click" />
    <asp:Button ID="btn2" runat="server"  OnClick="btn2_Click" />
    <asp:Button ID="btn3" runat="server"  OnClick="btn3_Click" />
</asp:Panel>

In the above example, btn2_Click event would fire when the user press Enter key.

No comments: