[英]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.