开发者

ASP.NET Custom Required Field Validator With CheckBox

开发者 https://www.devze.com 2023-03-10 14:38 出处:网络
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 u开发者_Python百科nless the associated check boxes ar

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 u开发者_Python百科nless 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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消