How JavaScript controls the execution of onclick in OnClientClick __java

Source: Internet
Author: User

OnClientClick is a client-side script, typically using JavaScript, running on the client, ie, and immediately after clicking.
OnClick is a server-side event handler, using C # or vb.net, on the server side, which is IIS, click the button, execute the postback, and then run.

If you want to call the OnClientClick before you call the OnClick event, you should return false in the OnClientClick event. If you do not return false, the OnClick event will continue to be invoked after the OnClientClick is executed.

The implementation method is as follows:

<asp:button id= "Btn_save" runat= "Server" text= "save" cssclass= "Button_bak" onclientclick= " return Whetherempty (); " onclick= "Btn_save_click"/>

JavaScript implementations are as follows:

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

Function Whetherempty ()
{
//alert ("KPI information cannot be all empty. ");
    emptflag = false ;
    var kpiname = document.getElementById ("<%=txt_KPIName.ClientID%>"). Value;
    var jobgoal = document.getElementById ("<%=txt_JobGoal.ClientID%>"). Value;
    var weight =  document.getElementById ("<%=txt_Weight.ClientID%>"). Value;
    var standard = document.getElementById ("<%=txt_Standard.ClientID%>"). Value;
   
    if (kpiname = "" && jobgoal = "" && weight = "" && Standard = = "")
    {
        Emptflag = true;
   }

if (Emptflag)
{
Alert ("KPI information cannot be all empty. ");
return false;
}

}
</script>

If onclientclick= " return Whetherempty ()" No return, in JavaScript even return Fales,onclick will still execute.

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.