[英]ASP.NET Custom Required Field Validator With CheckBox
Hello, I have to implement a form like above.你好,我必须实现一个像上面这样的表单。 Apart from other required fields, text boxes near the check boxes are not required to be filled in unless the associated check boxes are checked.
除其他必填字段外,除非选中相关复选框,否则不需要填写复选框附近的文本框。 How can i implement this.
我该如何实现这一点。 Thanks...
谢谢...
You can attach an onClick client side JS function and then you can enable/disable the validator via JS.您可以附加一个 onClick 客户端 JS function 然后您可以通过 JS 启用/禁用验证器。
<asp:CheckBox ID="" runat="server" OnClick="EnableDisable(this,ValidatorID)" />
<script type="text/javascript">
function EnableDisable(checkbox,ValidatorID){
var myVal = document.getElementById(ValidatorID);
ValidatorEnable(myVal, checkbox.checked);
}
</script>
Try this:尝试这个:
<asp:RequiredFieldValidator ... Enabled=<%# checkBox.Checked %> ... />
Here, you have to set the AutoPostBack
property value of the CheckBox
to true .在这里,您必须将
CheckBox
的AutoPostBack
属性值设置为true 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.