OnClick and OnServerClick

Source: Internet
Author: User

OnClick this keyword, it is the client JS script keyword, but also asp.net server control in the control properties, the latter is actually onserverclick.

The difference is that the former occurs on the client and the browser completes the operation, which needs to be loopback to the server side and run by the server side.

        If you are not a server-side control for code in generic HTML, you can use OnClick to define a client event. Onseverclick is the method   the server-side script calls;.

       , such as a button server control, can have both client and server-side onclick, in the order of first-client-server-side. But you need to be aware when defining:

       
<asp:button id= "cmdReturn2" on the page This OnClick in the  runat= "server"  onclick= "Returnfile" >Return</asp:Button>
defines the server-side event, because this is the control, Returnfile is a method that is defined in code.

        If you need to have the onclick in client JS at the same time, you need to pass the BUTTON.ATTRIBUTES.ADD in the code (" OnClick "," Return checkmailbox (); ") To join, is to return the result of the Checkmailbox () to the OnClick event, note ("onclick",  "return Checkmailbox") and ("onclick", "return  Checkmailbox ") is different, the former if the return False,onclick event will not execute, the latter regardless of return any value to carry on again.

       actually asp.net encapsulates a lot of things, and it makes it easy for a lot of new people to figure out what's going on, like the server-side click event mentioned above. In fact, this is not a real event, just let you have the feeling of the event, the essence is actually a post submission form, if Microsoft changed server-side onclick event name for onsubmit may be better understood.


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.