asp.net 中复选框的自定义验证器
我已经使用了自定义验证器,
protected void cvIsActive_ServerValidate(object source,ServerValidateEventArgs args)
{
if(args.Value.Length==1)
args.IsValid = true;
else
args.IsValid = false;
}
这是服务器验证的代码。我已经编写了检查其是否已检查的代码。 我已控制验证为复选框
<asp:CustomValidator runat="server" ErrorMessage="Please Select Status"
ID="cvIsActive" Font-Size="Smaller"
onservervalidate="cvIsActive_ServerValidate" ControlToValidate="chkIsActive"></asp:CustomValidator>
,但页面加载后立即出现错误
Control 'chkIsActive' referenced by the ControlToValidate property of 'cvIsActive' cannot be validated.
i have used custom validator
protected void cvIsActive_ServerValidate(object source,ServerValidateEventArgs args)
{
if(args.Value.Length==1)
args.IsValid = true;
else
args.IsValid = false;
}
this is code for server validate.. i have written to check whether its checked or not.
i have taken control to validate as checkbox
<asp:CustomValidator runat="server" ErrorMessage="Please Select Status"
ID="cvIsActive" Font-Size="Smaller"
onservervalidate="cvIsActive_ServerValidate" ControlToValidate="chkIsActive"></asp:CustomValidator>
but as soon as page loads it giving error
Control 'chkIsActive' referenced by the ControlToValidate property of 'cvIsActive' cannot be validated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要为 CustomValidator 将其与 CheckBox 一起使用时,只需在服务器验证中使用它,如下所示:
You don't need to set ControlToValidate property for CustomValidator when using it with CheckBox and simply use this in Server Validate like: