Onclick and onclientclick

Source: Internet
Author: User

OnclientclickIt is a client-side event processing method. It generally uses JavaScript for processing, that is, it runs directly on the IE end and runs at a click.

Onclick is the server-side event processing method. It runs on the server, that is, IIS. After you click it, execute PostBack before running it.

Onclientclick is often used for client detection. Of course, it can also be detected on the server side, but it requires interaction with the server, consuming resources and poor user experience.

When a widget has both onclick and onclientclick,OnclientclickBeforeOnclickRun

The correct statement should be:

< ASP: button ID = "Btnsave" Runat = "Server" Text = "Save" Onclick = "Btnsave_click" Onclientclick = "Return savefunc ();"   />

 

Savefunc verifies the data. When the verification passes and returns true, the server-side method is saved. If the verification fails, false is returned, and the server-side saving method is not executed.

Incorrect syntax:

Code

<! -- Whether the verification is successful or not, the server-side method is executed and cannot be used for verification. -->
< ASP: button ID = "Btnsave" Runat = "Server" Text = "Save" Onclick = "Btnsave_click" Onclientclick = "Savefunc ();"   />

returns false regardless of the verification result, the server-side method will never be executed -->
Asp: button id =" btnsave " runat =" server " text =" save " onclick =" btnsave_click " onclientclick =" savefunc (); Return false; " />

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.