Click here to Skip to main content
15,891,976 members
Articles / Web Development / ASP.NET
Alternative
Tip/Trick

How to prevent textbox postback when hitting Enter key in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.91/5 (9 votes)
24 Oct 2011CPOL 27.6K   6
This seems to do the job:

This seems to do the job:


ASP.NET
<asp:textbox id="tbTest1" runat="server" onkeypress="return event.keyCode != 13;" />

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralReason for my vote of 5 Excellent concise answer Pin
tonysawyer2-Nov-11 1:11
tonysawyer2-Nov-11 1:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.