CustomValidator 控件
CustomValidator 控件可使用您自己编写的验证逻辑检查用户输入。此类验证使您能够检查在运行时派生的值。
CustomValidator 可与另一个控件(例如 TextBox 控件)结合使用。请先将要验证的控件添加到网页中,再添加 CustomValidator ,这样就可以轻松地将 CustomValidator 与该控件关联。
向网页中添加 CustomValidator 控件
将 CustomValidator 控件从“工具箱”面板拖到网页上。
在“设计”视图中,选择 CustomValidator ,右键单击该控件,然后在快捷菜单上单击“属性”。
在“标记属性”面板中,从 ControlToValidate 属性下拉列表中选择要使用 CustomValidator 进行验证的控件。
若要在客户端浏览器中验证该控件,请将 ClientValidationFunction 设置为要在验证中使用的 JavaScript 函数的名称。
有关编写用于 CustomValidator 控件的客户端或服务器函数的信息,请参阅 MSDN Library 中的如何:使用自定义函数对 ASP.NET 服务器控件进行验证
。
如果要使用 ValidationSummary 控件来合并验证错误消息,请将 ValidationGroup 属性设置为验证控件组的名称。这可以是任意字符串,只要组中的所有控件都具有相同的值即可。
有关 CustomValidator 控件的所有属性的完整说明,请参阅 MSDN Library 中的 CustomValidator 成员
。
有关使用验证控件验证用户输入的详细信息,请参阅 MSDN Library 中的帮助主题 -- 验证控件
。
另请参阅
概念
ASP.NET 验证控件
RangeValidator 控件
RegularExpressionValidator 控件
RequiredFieldValidator 控件
ValidationSummary 控件