1.
In depth, this is not an ASP. NET issue, but how the submit button of the HTML form is designed.
When the focus of your cursor enters a form element, the first button in the form (flow layout follows left to right, top to bottom) type = submit (if any) will be activated ), wait for the response to the carriage return event and submit the form
You can test it. 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, no additional script is required to submit the form. The submit button is designed to submit the form.
In 1.x, it is displayed as <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 defualtbutton of the form element as follows:
<Form ID = "form1" runat = "server" defaultbutton = "button1">
Pay attention to defaultbutton = <targetbutton. ID>. Therefore, the buttons in the composite control such as the template may be invalid (not tested)
2.
Modify the button Rendering Method usesubmitbehavior = "false"
<Asp: button id = "button1" runat = "server" text = "button" onclick = "button#click" usesubmitbehavior = "false"/>
(Csdn Xiaofeng residual month)
In addition, you can filter the carriage return practices by controlling the focus. You need to record it to obtain the ID of the control where the current page focus is located:
Document. activeelement
For ASP. NET.Textbox1After the content is entered, press enter to execute the button1 click method. Write it 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 };");