asp.net different onclick event difference Summary (Onserverclick,onclientclick) _ Basic Application

Source: Internet
Author: User
Tags button type
1. HTML controls, such as the IMG input button, etc. onclick (client) and OnServerClick(Service-side) event, note runat= "Server" ...

The onclick here is performed prior to OnServerClick.
2.WEB controls, such as OnClientClick (client) and onclick (server-side) events such as the <asp:button button ...

The OnClientClick here is executed before the onclick.
The OnClientClick event comes from 2.0, which replaces the following code ...

In summary, client-click events are performed prior to the server-side click event. That is, the client's JavaScript is executed first, and then the server-side code is executed.

Attachments: HTML controls, HTML server controls, and Web user controls
ASP.net is now easy and quick to develop, the key is that it has a powerful set of control libraries, including Web server controls, Web user controls, Web custom controls, HTML server controls, HTML controls, and so on. This is mainly about the differences between HTML controls, HTML server controls, and Web server controls.
1, HTML control: is our usual HTML language tags, these language tags in the past static pages and other Web pages exist, not in the server-side control, only in the client through JavaScript and VBScript and other programming languages to control. <input type= "button" id= "BTN" value= "button"/>
2, HTML server control: is actually HTML control based on the runat= "server" composed of the control. Their attention difference is that the HTML control runs on the client, and the HTML server control runs on the server side. Reference to other information is said: When the ASP.net Web page is executed, will check the annotation has no runat attributes, if the annotation is not set, then the HTML callout will be treated as a string, and sent to the string stream waiting to be sent to the client, the client's browser will explain it If the HTML annotation has a set runat= "server" attribute, the Page object puts the control into the controller, which is controlled by the server-side code, and then converts the execution result of the HTML server control to an HTML callout when the control is finished. It is then sent to the client as a string stream to interpret <input id= "button" type= "button" value= "button" runat= "Server"/>
3, Web server control: Also known as ASP.net server control, is the basic element of Web Form programming, but also unique to asp.net. Instead of directly describing HTML elements, it produces one or more HTML controls according to the client. such as: <asp:button id= "Button2" runat= "Server" text= "button"/> So what's the difference between it and HTML server controls? The views of other Web pages are as follows:
1), ASP.net server controls provide a more unified programming interface, such as each ASP.net server control has the Text property.
2, hide the client's differences, so that programmers can put more effort on the business, and do not have to consider whether the client's browser is IE or Firefox, or mobile devices.
3, ASP.net server control can save the state to the viewstate, so that the page is uploaded from the client back to the server or from the server to download to the client process can be saved.
4, the event handling model is different, the HTML annotation and the HTML server control's event processing are on the client's page, but the ASP.net server control is on the server, for example:
<input id= "Button4" type= "button" value= "button" runat= "Server"/> is HTML server control, when we click this button, the page will not be uploaded back to the server side, The reason is that we did not define a mouse click event for it.
<input id= "Button4" type= "button" value= "button" runat= "Server" onserverclick= "test"/> We added a OnServerClick event to the HTML server control, and clicking the button page sends it back to the server side and executes the test (object sender, EventArgs e) method.
<asp:button id= "Button2" runat= "Server" text= "button"/> is a asp.net server control, and we do not define click for it, but when we click, the page is also sent back to the server side.
This shows that: HTML annotation and HTML server control events are triggered by the page, and the ASP.net server control is the page to send the form back to the server side, by the server to deal with.

the difference between Onclick,onclientclick and OnServerClick

The following are the HTML buttons (system.web.ui.htmlcontrols) and ASP. NET service-side button (

System.Web.UI.WebControls) as an example:
1. HTML controls, such as the onclick (client) and OnServerClick (server-side) events of an IMG input button,

Note runat= "Server" ...
<input type= "button" id= "btn" name= "btn" value= "button" runat= "Server" onserverclick= "serversideevent" onclick= " Sidescript "/>

The onclick here is performed prior to OnServerClick.
2.WEB controls, such as OnClientClick (client) and onclick (server-side) events such as the <asp:button button ...

<asp:button id= "btn" text= "button" runat= "Server" onclick= "Sidescript" onclientclick= "Clientsidescript"/>

The OnClientClick here is executed before the onclick.
The OnClientClick event comes from 2.0, which replaces the following code ...

Btn. Attributes.Add ("onclick", "sidescript");

In summary, client-click events are performed prior to the server-side click event. That is, the client's JavaScript is executed first, and then

To the server side to execute the relevant code for the server.

ASP. The difference between onclick and OnServerClick events in net

For a server button control (that is, a button of type <asp:Button>):
Server Response Event: OnClick
Client Response Properties: OnClientClick

For HTML button controls (that is, <input type= "button" runat= "Server" >)
Server Response Event: OnServerClick
Client Response event: OnClick
Asp:button type is the onclick
<input type= "button" runat= "Server"/> type is OnServerClick
One is a. NET control ~ one is an HTML control converted to a server-side control
Effect exactly the same, should be the input itself with onclick client events, Microsoft can only use OnServerClick as the name of the server-side response

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.