Sequence and condition of OnClick and OnClientClick

Source: Internet
Author: User

OnClick and OnClientClick really took some time to figure out for cainiao. OnClientClick is run on the client. OnClick will run postback on the server ). However, there are execution time and conditions. Time Sequence: When a button is clicked on a webpage, The OnClientClick of the client is triggered first, and then the OnClick line is merged. Condition: OnClick will be executed only when OnClientClick returns true. By default, the OnClientClick function returns true if the OnClientClick function does not return a value. Therefore, the OnClick function can be executed smoothly. However, there are also some values that do not allow OnClick execution in some cases. For example, you can use Javascript to perform the first-level verification or basic checks. If the conditions are not met, OnClick is not triggered to return to the server to continue the logic.

In this case, the response of OnClientClick must be artificially set to false. The procedure is simple. Defines a Javascript or vbscript function that returns true or false values based on the detection conditions. Then it is called in OnClientClient. The method is OnClientClick = "return fun (the Javascript or vbscript function you defined);" in this way, OnClick is triggered only when the condition is met. If the condition is not met, OnClick is not triggered.

 

The younger brother was not long before he started writing asp.net. It is a dish in the dish. So I am not familiar with many things. Here I will share my daily work experience. Thank you for your advice.

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.