简体   繁体   English

如何在ASP.NET中触发自定义验证器事件?

[英]How to get custom validator event to fire in asp.net?

I am using custom validator tool in asp.net to check whether a text box is blank or not(I did not use requiredfieldvalidator because the text box in question is going to be enabled occasionally).The problem is that the custom validator event in code behind is not firing at all.This is the source code: 我在asp.net中使用自定义验证器工具检查文本框是否为空(我不使用requiredfieldvalidator,因为有问题的文本框将偶尔启用)。问题是代码中的自定义验证器事件后面根本没有触发。这是源代码:

<asp:TextBox ID="txtS_rentSDate" runat="server" Font-Names="Bookman Old Style" 
                Font-Size="Medium" Width="326px" 
                ontextchanged="txtS_rentSDate_TextChanged" 
                CausesValidation="True"></asp:TextBox>    

<asp:CustomValidator ID="cvRentSDate" runat="server" 
                ControlToValidate="txtS_rentSDate" 
                ErrorMessage="Please enter the rent start date" 
                onservervalidate="cvRentSDate_ServerValidate" ValidateEmptyText="True" 
                Width="180px"></asp:CustomValidator>

Code behind: 后面的代码:

protected void cvRentSDate_ServerValidate(object source, ServerValidateEventArgs args)
{
    args.IsValid = (args.Value.Length > 0);
}

Kindly let me know where I am going wrong and what is the proper way to do it? 请让我知道我要去哪里了,正确的方法是什么?

<asp:CustomValidator ID="cvRentSDate" runat="server" 
            ControlToValidate="txtS_rentSDate" 
            ErrorMessage="Please enter the rent start date" 
            OnServerValidate="cvRentSDate_ServerValidate" ValidateEmptyText="True" 
            Width="180px"></asp:CustomValidator>

Try with my above lines. 尝试用我上面的话。 May be you need to use OnServerValidate instead of onservervalidate. 可能是您需要使用OnServerValidate而不是onservervalidate。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM