繁体   English   中英

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

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

我在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>

后面的代码:

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

请让我知道我要去哪里了,正确的方法是什么?

<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>

尝试用我上面的话。 可能是您需要使用OnServerValidate而不是onservervalidate。

暂无
暂无

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

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