Enabling or disabling a validator control in javascript

Posted by Dan on July 21, 2011 in Development, Tutorials |

Recently I had to have a form that had a requiredfieldvalidator that was supposed to validate only on certain conditions. I did not want the validator to validate its control (textbox B) unless textbox A had a value in it. I decided the best way to do this was to capture the keyup event of textbox A and if there was a value in the textbox, to turn the validator for textbox B on. To do that via javascript, you have to utilize the asp.net built in javascript function ValidatorEnable.

<script type="text/javascript">
    var makeEnabled = true;
    var validatorControl = document.getElementById('<%= RequiredFieldValidator1.ClientID %>');
    ValidatorEnable(validatorControl, makeEnabled);
</script>

Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Copyright © 2010-2012 Dan Appleyard All rights reserved.
Desk Mess Mirrored version 1.9 theme from BuyNowShop.com.

Load Times Plugin made by Cheap Web Hosting