zoukankan      html  css  js  c++  java
  • 验证控件的一点心得

    与其说是心得,不如说是疑惑,之前基本没用过验证控件,觉得太丑又不好用,这次因为是为了跟维护的系统原来的风格保持一致,所以选择使用,

    因为页面字段太多,都需要做非空验证,而且要求错误信息都一次性显示在最上面,所以我的想法是用RequiredFieldValidator和ValidationSummary两个控件结合使用,

    没用不知道一用吓一跳,出错了,错误又给屏蔽了,只能去查log,仔细看了下,错误信息是:Control 'OSchoolCode' referenced by the ControlToValidate property of 'RequiredFieldValidatorSchoolCode' cannot be validated.

    又换成CustomValidator控件试试,还是同样的错误:Control 'OSchoolCode' referenced by the ControlToValidate property of 'CustomValidatorSchoolCode' cannot be validated.

    其中的OSchoolCode是个Label,难道这些验证控件不能验证Label?网上找了半天只找到怎么使用验证控件的,没有对CONTROLTOVALIDATE所对应的控件类型做出说明,只说这是需要验证的控件的ID。所以在此向知道的园友求证我的结论是否正确,不甚感激!

    经过测试,在此纠正一下:

    用CustomValidator可以验证label控件,ControlToValidate这个属性设置为空就可以,不会出现Control '' referenced by the ControlToValidate property of 'CustomValidator' cannot be validated这种错误,然后剩下的验证逻辑在ServerValidate或者ClientValidationFunction去实现。

  • 相关阅读:
    我的大学学习之路
    拉勾上的一道题目
    python中文处理之encode/decode函数
    几个容易出错的css盒子模型细节
    洗牌算法shuffle
    判断正整数是否对称
    一种快速求fibonacci第n个数的算法
    利用正则表达式作为string.split seprator
    docker部分命令
    idea上传项目到GitHub
  • 原文地址:https://www.cnblogs.com/pfs1314/p/2119739.html
Copyright © 2011-2022 走看看