Onclientclick It is the client event method. Generally, JavaScript is used for processing. That is, it runs directly on the IE side. Click it to run.
Onclick An event is a server-side event processing method. It runs on the server, that is, IIS. click the button, execute PostBack, and then run. if we have both the client's onclientclick method and the onclick event processing method on a button, how can we operate according to the normal logic.
In onclientclick, we often perform client detection. of course, you can perform the same check on the server, but the price for doing so is to interact with the server, consume resources, and the user experience is poor... example:
// Jsdel () is a JavaScript function.
<Asp: button id = "btndel" width = "80px" cssclass = "buttonstyle"
Runat = "server" text = "delete" onclientclick = "Return jsdel ();"
Onclick = "btndel_click1"/>
It should be noted that when we click this button, the client automatically runs first and then the server. if the client returns false, the corresponding method on the server will never be executed. in this way, the server-side method is executed only when the detection succeeds.
That is to say, if we write:
<Asp: button id = "btndel" width = "80px" cssclass = "buttonstyle"
Runat = "server" text = "delete" onclientclick = "jsdel (); Return false ;"
Onclick = "btndel_click1"/>
No matter how jsdel is executed, the btndel_click1 method corresponding to the server will never be executed. Because return false makes the Client Always return false.
If we write:
<Asp: button id = "btndel" width = "80px" cssclass = "buttonstyle"
Runat = "server" text = "delete" onclientclick = "jsdel ();" onclick = "btndel_click1"
/>
Then btndel_click1 will happen, and it will not be able to achieve the same effect. That is to say, if you do not pass the detection, you will also execute the server method.
So you must pay attention to it.
Of course, we can use the BTN. Attribute. Add () method to perform similar processing.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/shiling_02404/archive/2009/03/27/4028268.aspx