Introduction to the button in ASP. NET

Source: Internet
Author: User

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.

 
 
  1. Function document. onkeydown ()
  2. {
  3. If (Event. keyCode= 13)
  4. {
  5. Button. click (); // click the Enter key to call the button click event
  6. Event. returnValue=False; // Cancel the default operation of the enter key
  7. }
  8. }

If the button is a server button, the changes are as follows:

 
 
  1. Function document. onkeydown ()
  2. {
  3. // Use document. getElementById to obtain the Button Object
  4. VarButton=Document. GetElementById ('<= ServerButton. ClientID %>');
  5. If (Event. keyCode= 13)
  6. {
  7. Button. click ();
  8. Event. returnValue=False;
  9. }
  10. }

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.

  1. ASP. NET calls the WCF Service
  2. Analysis of ASP. NET verification controls
  3. Compatibility between the WCF Service and ASMX service in ASP. NET
  4. ASP. NET Applications
  5. ASP. NET HttpModule

Related Article

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.