OnClientClick的用法

摘自:http://blog.csdn.net/coolpig86/article/details/5439560

 OnClientClick用于执行客户端脚本.当我们单击一个按钮时,最先执行的是OnClientClick 事件,根据OnClientClick 事件的返回值来决定是否执行OnClick事件来postback页面.其返回值为true 和 false,默认情况下OnClientClick 返回值为真.

通过这个属性,可以去验证一个服务端控件了,而且不用回传服务器。。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <mce:script type="text/javascript" ><!--
       var CheckForm=function(){
         var content=document.getElementById("tx_Content").value;
         if(content==""){alert("内容不能为空");return false;}
       }   
// --></mce:script>
</head>
<body>
    <form id="form1" runat="server">
    <div>      
        <asp:TextBox ID="tx_Content" runat="server"></asp:TextBox>
        <asp:Button ID="bt_OK" runat="server" Text="提交" OnClientClick="return CheckForm();" />
    </div>
    </form>
</body>
</html>

当然,这里只是一个简单的非空验证,其它的验证同理可得。。

--------------------->>>>

原文地址:https://www.cnblogs.com/KeenLeung/p/3866196.html