1. In depth, this is not a problem with Asp.net, but how the submit button of the HTML form is designed.
When your cursor focus enters a form element, the first (
Stream layout follows left to right, top to bottom)
Type = submit button (if any), wait for the response to the carriage return event, and submit the form
You can test the code.
<Form action = "">
<Input type = "text"/>
<Input type = "Submit" value = "Submit"/>
</Form>
<Form action = "">
<Input type = "text"/>
<Input type = "button" value = "Submit"/>
</Form>
2. In Asp.net 2.0, the button is displayed as <input type = submit> by default.
In this case, do not submit the form with additional scripts. The submit button is designed to submit the form.
But in 1. <Input type = button onclick = _ dopostback ()/>
This normal button does not have the above default behavior of submit.
3. To disable this default action, follow these steps:
1. Set defaultbutton of the form element as follows.
<Form ID = "form1" runat = "server" defaultbutton = "button1">
Pay attention to defaultbutton = <targetbuttonid>. Therefore, the buttons that conform to the control summary, such as the template, may be invalid.
2. Modify the button Rendering Method usesubmitbehavior = "false"
<Asp: button id = "button1" runat = "server" text = "button" onclick = "button#click" usesubmitbehavior = "false"/>
In addition, you can filter the carriage return practices by controlling the focus. You need to record it to obtain the ID of the Child control of the current page focus.
Document. activeelement
For Asp.net, after entering the content in the textbox, press enter to execute the click method of button1. In
In the page_load event method.
Textbox1.attributes. Add ("onkeydown", "If (event. Which | event. keycode) {if
(Event. Which = 13) | (event. keycode = 13 )){
Document. getelementbyid ('"+ button1.uniqueid +"'). Click (); Return
False ;}} else {return true };");
$ (Document ). ready (function ({$ (": Text "). keypress (function () {If (E. keycode = 13) {$ (": Input "). unbind ("click"); $ ("# B "). fuous (); $ ("# B "). click ()}});});