zoukankan      html  css  js  c++  java
  • 同一个页面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>
  • 相关阅读:
    Language Integrated Query
    为什么说 LINQ 要胜过 SQL
    LINQ(Language Integrated Query)
    Rx (Reactive Extensions)介绍
    ReactiveX Operators
    ReactiveX
    给 iOS 开发者的 RxSwift(一)
    The features of Swift
    RxSwift源码与模式分析一:基本类
    智力
  • 原文地址:https://www.cnblogs.com/lljinz/p/2441827.html
Copyright © 2011-2022 走看看