Resolve an ASP page return postback issue

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.