The ASPNET button only executes the client code does not echo the page implementation idea _ Practical skills

Source: Internet
Author: User
The asp.net button default behavior is to post the page back and execute the server code. You can also use the HTML button control input type= "button" in the page, but this HTML control is not referenced in the CS file.

Asp:button is available in the CS file, how do I make it execute client-side JavaScript code instead of loopback execution server code?

First, introduce the Asp:button two events OnClientClick and OnClick, the former onclientclick is the execution of client JavaScript code, the latter onclick is the server code, the first to perform postback, and then run at the server. OnClientClick to the onclick, if the Asp:button without onclick, click will be echoed.

When OnClientClick returns false, the onclick is not executed. This allows an AJAX asynchronous operation to be performed in OnClientClick.
Copy Code code as follows:

<asp:button id= "btnsave" runat= "Server" text= "Save" onclientclick= "Ajaxdosave" (); return false; "/>

This button becomes the input of the client, but can also be referenced in the CS file.
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.