我正在学习如何使用自定义验证器进行服务器端验证,但我似乎无法让它工作。每当我单击按钮时,文本框为空,错误消息不会显示。我究竟做错了什么?
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" ControlToValidate="TextBox1"
OnServerValidate="CustomValidator1_ServerValidate" ValidationGroup="ValidateGp"
ErrorMessage="This is a custom error validator" runat="server"/>
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="ValidateGp"/>
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (args.Value.Equals(string.Empty))
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}