ASP.NET服务器控件与客户端控件OnClientClick和OnClick的用法比较

2019-02-19 12:44:05 浏览数 (1)

OnClientClick和OnClick的用法比较

<head runat="server">     <title>无标题页</title>     <script language="javascript">     function check()     {            var email = document.getElementById('TextBox1');         var pwd = document.getElementById('TextBox2');         if  (email.value=="" || pwd.value=="")         {             alert("请填写完整内容");             return false;         }         else         {             var mailStr = /(("w) )@(("w) ).[cc|com|net|org|tv|cn]/ig;             if (!mailStr.exec(email.value))             {                 alert('Email地址书写不正确!"n请您重新输入!');                 email.value = '';                 email.focus();                 return false;             }                     }            }     </script> </head> <body>     <form id="form1" runat="server">     <div>         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;         <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>         <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return check();" OnClick="Button1_Click1"  />

    </div>     </form>

</body>

先执行客户端的javascript函数,页面回送以后再执行服务器端的方法 onclientclick是客户端事件,onclick是服务器端事件。并且客户端事件先执行,服务器端事件后执行。  

0 人点赞