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.