Because asp.net adopts the event-driven mode, The onclick event of the button is not triggered by pressing the carriage return by default. If you press enter, the form is not submitted. You can see through httpwath that the page form is actually submitted to the action page under the form, but the onclick event is not triggered, if you are interested in the introduction of event-driven in asp.net, it may be helpful to solve the problem of trigger different events by multiple buttons on a single page, this avoids the trouble of requiring multiple forms in asp or controlling them through js scripts.
Asp.net brings convenience, but also brings about a problem. In actual applications, there are not many buttons on a page. After entering the content in the input box, you can press enter to submit the form. Because asp.net adopts the event-driven mode, The onclick event of the button is not triggered by pressing the carriage return by default. If you press enter, the form is not submitted. You can see through httpwath that the page form is actually submitted to the action page under the form, but the onclick event is not triggered.
In the asp.net event-driven mode, to trigger an event by pressing the carriage return, you must use the js script.
In asp.net's aspx page, form code:
The Code is as follows:
However, you can see in the source code of the access page:
The Code is as follows:
By default, press enter in the input box. In fact, the form is submitted to the corresponding page of the form action, and no event is triggered.
Strange: When a web control is not used on An aspx page, press enter in the input box. By default, The onclick event of a button is not triggered; when a web control is used on the page, press enter in the input box. By default, The onclick event of the first button is triggered. [Here refers to the first button control in the page code, including the button control in the web Control]
The following describes how to trigger the onclick event of the button through js.
The default button control, the code in html is as follows:
The Code is as follows:
In fact, The onclick event triggered by clicking this button calls a js script __dopostback (eventTarget, eventArgument)
The button control has a property: UseSubmitBehavior. The default value is true. When you change it to false, you can view the html source code to see the called js Script Function.
The Code is as follows:
Generated js script:
The Code is as follows: