OnClientClick is a client-side event for button

Source: Internet
Author: User

OnClick is a server-side event for a button

OnClientClick is a client-side event for button

Generally we use OnClientClick to verify our submission data, but this must return ture or false, that is, must add return, otherwise the onclick fails. When False is returned, the onclick server-side event is aborted, and when your JS verification has an error, it also skips the validation and executes the server-side event OnClientClick directly.

Example: Click the button to determine whether the text box is empty

In an. aspx file, you can write as follows:

<asp:textbox id= "Pwdtext" runat= "Server" textmode= "Password" > </asp:TextBox>

<asp:imagebutton id= "OKButton" runat= "Server" onclientclick= "return Checkinput ();" text= "OK"/>

<script type= "Text/javascript" language= "JavaScript" >

function Checkinput ()

{

if (document.getElementById ("<%=pwdtext.clientid%>"). Value = = "")//With Master method

{

Alert ("Please fill in the password!") ");

return false;

}

return true;

}

</script>

If you do not have a master or if the document.getElementById ("Pwdtext"). value.length==0) is empty,

OnClientClick is a client-side event for button

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.