In the ASP. NET page in the text box, button and other server controls to enter the page will cause the postback, many online solution is to use JS to event.keycode==13 determine whether to press the ENTER, if it is Event.returnvalue = false; But this can only apply to IE, some browsers do not support Event.keycode, for example: Firefox is the use of Evt.which.
Here to give you a plan, after the use of the feeling is OK, if there are problems please forgive, give advice:
Page code:
<%@ Page language="C #"autoeventwireup="true"codefile="Default.aspx.cs"inherits="_default"%><! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">"http://www.w3.org/1999/xhtml">"Server"> <title></title>"Form1"runat="Server"defaultbutton="Button1"> <div> <asp:textbox id="TextBox1"runat="Server"></asp:TextBox> <asp:button id="Button1"runat="Server"text="Button"Enabled="False"style="Display:none"/> <br/> <asp:textbox id="TextBox2"runat="Server"></asp:TextBox> <asp:button id="Button2"runat="Server"text="Button"/> </div> </form></body>1, first to the page form set DefaultButton (here is set Button1).
Function: The button is clicked to submit the form for postback when the carriage returns.
2. Set enabled= "False" for Button1
Role: Enter after the discovery Button1 can not be used, so this submission will not be successful
3, if you do not want to see this Button1, add style style= "Display:none" to hide
Note: You cannot set the hide by the visible of the button, because this hides the carriage return or the postback
Resolve an ASP page return postback issue