On the ASP. NET webpage, use the server button. By default, the first button responds to the button clicking event. Most of the time, the first button is not something the user wants to do after clicking enter. Generally, the Enter key is used to submit data after the input is completed, for example, close the current pop-up window, enter a keyword, and press enter to search.
The solution for setting the Enter key on the ASP. NET webpage is to use the document. onkeydown () method of javascript to capture the keyboard Click event and use event. keyCode to obtain the key position clicked by the user.
- Function document. onkeydown ()
- {
- If (Event. keyCode= 13)
- {
- Button. click (); // click the Enter key to call the button click event
- Event. returnValue=False; // Cancel the default operation of the enter key
- }
- }
If the button is a server button, the changes are as follows:
- Function document. onkeydown ()
- {
- // Use document. getElementById to obtain the Button Object
- VarButton=Document. GetElementById ('<= ServerButton. ClientID %>');
- If (Event. keyCode= 13)
- {
- Button. click ();
- Event. returnValue=False;
- }
- }
If the button is in the user control, the above method can be used in the user control. You must cancel the default operation of the enter key. Otherwise, the default button will continue after ASP. NET executes the button.
- ASP. NET calls the WCF Service
- Analysis of ASP. NET verification controls
- Compatibility between the WCF Service and ASMX service in ASP. NET
- ASP. NET Applications
- ASP. NET HttpModule