简体   繁体   English

具有ClientValidationFunction的ASP.NET CustomValidator

[英]ASP.NET CustomValidator with ClientValidationFunction

I'm trying to validate an integer range with a CustomValidator. 我正在尝试使用CustomValidator验证整数范围。 The range is set dynamically, so when either the min/max values on my usercontrol change, the client validation function is updated. 该范围是动态设置的,因此当我的usercontrol上的最小值/最大值改变时,客户端验证功能也会更新。 However, I can't get the validation function to fire. 但是,我无法启动验证功能。 I have this code: 我有以下代码:

<asp:CustomValidator ID="vldAnswerValid" runat="server" ControlToValidate="txtAnswer" Display="Dynamic" SetFocusOnError="true" ValidationGroup="answer" OnServerValidate="vldAnswerValid_ServerValidate" Enabled='<%# !IsReadOnly %>' />

Setting the function from the codebehind with: 使用以下代码从代码后面设置功能:

vldAnswerValid.ClientValidationFunction = " function(oSrc, args){ alert(1); args.IsValid = false; } ";

But there's no message displayed and no alert. 但是没有显示任何消息,也没有警报。 Am I missing something? 我想念什么吗?

EnableClientScript属性设置为True。

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

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