• 在usercontrol中如何使用验证控件CustomValidator 中的客户端验证


    在用户控件中,为一个文本控件添加CustomValidator验证,然后设置CustomValidator 的ClientValidationFunction 属性为客户端的Validate(source,args)方法,

    如果在一个页面有两处地方用到了这个用户控件,然后点击save button 验证的时候,就会发现,这个验证不是自己想要的那种验证,这是为什么呢,原来,用到用户控件的两处

    地方生成了两个Validate方法,但是只有一个方法被用到了,所以只能验证其中的一个,如果要使两个都验证,那就要给ClientValidationFunction 指定不同的方法才行,

    可以采取如下步骤:

    在UserControl.cs 中,为ClientValidationFunction 赋值,CustomValidatorID.ClientValidationFunction  =CustomValidatorID.ClientID+”你的方法名”

    在ascx页面中 ,写验证方法为 function <%=CustomValidatorID.ClientID%>你的方法名(source,args){……},

    通过以上操作,就能做到CustomValidator在客户端的验证了

  • 相关阅读:
    62. Unique Paths
    24. Swap Nodes in Pairs
    83. Remove Duplicates from Sorted List
    21. Merge Two Sorted Lists
    141. Linked List Cycle
    268. Missing Number
    191. Number of 1 Bits
    231. Power of Two
    9. Palindrome Number
    88. Merge Sorted Array
  • 原文地址:https://www.cnblogs.com/lavenvsxiaoye/p/3585479.html
Copyright © 2020-2023  润新知