The following does not work and is here only for historical reasons.
You have probably read Scott Hanselman's article on How to create a Default "Enter" Button for Forms/PostBacks. I just wanted to do a little update as the Page.RegisterHiddenField method is now obsolete. If you try the above, Visual Studio will helpfully remind you of the fact and suggest that you use ClientScript.RegisterHiddenField(string, string) instead. So here it is:
public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { UseEnterKeyForGenerateDrawings(); } private void UseEnterKey() { ClientScript.RegisterHiddenField("__EVENTTARGET", "btnSearch"); } }
<asp:button id="btnBuy" onclick="btnBuy_Click" runat="server" text="Search"></asp:button>
private void UseEnterKey() { ClientScript.RegisterHiddenField("__EVENTTARGET", "btnBuy"); }