OnClick Events and OnServerClick events

Source: Internet
Author: User

1. For Web controls only, the OnClick event executes the code in the client.

<%@ Page Language="C #"AutoEventWireup="true"codebehind="Click.aspx.cs"Inherits="Onclickandonserverclick.click" %><!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Headrunat= "Server"><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/>    <Scriptsrc= "A.js"></Script>    <title></title></Head><Body>    <formID= "Form1"runat= "Server">  <%--onclick="Myonclick ()"--%>      <%--OnServerClick="Btn_clickserver"--%>        <inputtype= "button"onclick= "Myonclick ()"ID= "BTN1"value= "button" />    </form></Body></HTML>

You can write the event on an HTML page or in the called JS file (A.js here).

A.js:

function Myonclick () {    alert ("triggers the onclick event!) ");} function del () {    alert ("OK");}

Operation Result:

2.onserverclick event, this is the method of executing the service side.

<type= "button"  onserverclick= "Btn_clickserver"     ID  = "BTN1"  value= "button"  runat= "Server"/>

Corresponding events are supplemented in the background:

 Public void btn_clickserver (object  Sender,eventargs e)        {                        string' <script>alert (' You triggered the Onclickserver event ');</script> " ;            Response.Write (str);            Response.End ();        }

Execution Result:

Note that when the OnClick event is used with the OnServerClick () event, the OnClick event executes first, but be careful not to add the runat= "server" attribute and the no-client JS file cannot be called.

OnClick Events and OnServerClick events

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.