• 同一个页面Button OnClientClick事件 和服务器验证控件提交问题


    实现功能:
        
            点击Button按钮的OnClientClick事件,不会影响服务器验证控件的验证功能
                                                    (验证不通过,则不提交服务器页面)
    背景:
           1. 在同一个页面有服务器验证控件(RegularExpressionValidator),多个
           2. 有Javascript函数,实现验证和其他功能
           3. Button按钮,有两个事件OnClick,OnClientClick
    方法:

        HTML页面
        验证控件:

     程序代码

    <asp:TextBox ID="txt_Test" runat="server" Width="120px" MaxLength="8"></asp:TextBox>
                            <asp:RegularExpressionValidator ID="validator_Test" runat="server" ControlToValidate="txt_Test"
                                ErrorMessage="数字" ValidationExpression="^\d+$"></asp:RegularExpressionValidator>



    按钮:

      程序代码


    <asp:ImageButton ID="btnPutin" runat="server" Text=" 提 交 " OnClick="btnPutin_Click"
                                OnClientClick=" if(CheckClientValidate()) { return CheckNullValue()}" ImageUrl="../images/submit1.gif" />


    脚本:

      程序代码


    <script type="text/javascript">    
    //返回,服务器验证控件是否成功
    //Author:  ADD by Aprillee at 2007-12-27
    //Example: OnClientClick="if(CheckClientValidate()) { return CheckNullValue()}"
    function CheckClientValidate(){
            
           Page_ClientValidate();
           if (Page_IsValid){
               return true;
           }else{
               return false;
           }
         }
    // 以下为自定义脚本功能
    function CheckNullValue()
        {
            alert('Test');
        }
    </script>
  • 相关阅读:
    OpenSSL 安装 (Linux系统)
    JVM 指令集
    Github清除历史提交,保留最新提交
    php7+apache2.4 安装(window)
    mysql 函数模拟序列
    SpringBoot配置成Liunx服务
    Liunx下NFS服务器的搭建与配置
    Laravel 出现"RuntimeException inEncrypter.php line 43: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths."问题的解决办法
    win7安装laravel
    win7安装composer
  • 原文地址:https://www.cnblogs.com/lljinz/p/2441827.html
Copyright © 2020-2023  润新知