OnClick and OnClientClick

Source: Internet
Author: User

OnClientClick is a client-side event-handling method that is typically handled using JavaScript, which is run directly on the IE side, with a single click.

The onclick is the server-side event handling method that runs on the server side, IIS, and then executes the postback before running

OnClientClick are often used to perform some client-side testing. Of course, it can also be placed on the server side of the detection, but need to interact with the server, consume resources, and the user experience is not good.

When there is both OnClick and OnClientClick on a control,OnClientClick executes before the onclick

The correct wording should be:

<asp:button id= "btnsave" runat= "Server" text= "Save" onclick= "Btnsave_click" onclientclick= "return Savefunc ();"/ >

The SAVEFUNC validates the data, and when the validation is performed by returning true, the server-side method is saved, and the server-side save method is not executed by the validation without returning false.

The wrong wording:

<!--performs a server-side approach regardless of whether validation is passed, and does not achieve the purpose of verification-
<asp:button id= "btnsave" runat= "Server" text= "Save" onclick= "Btnsave_click" onclientclick= "Savefunc ();"/>

<!--returns false regardless of the validation result, the server-side method never executes--
<asp:button id= "btnsave" runat= "Server" text= "Save" onclick= "Btnsave_click" onclientclick= "Savefunc (); return false; "/>

OnClick and OnClientClick

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.