Let's take an example of payment options and required fields on an Asp.Net page: Say we have Credit card option and other payment option like PayPal or so. If CC is chosen, then we want to enforce the required validator on CC fields and otherwise not. And we want to do it in JavaScript - a simple way to go is to use the ValidatorEnable method -
ValidatorEnable(document.getElementById('<%=rqrdtxtCCNumber.UniqueID.ToString().Replace("$", "_")%>'), true);
Plus a trick I used recently with this method is to force the validity of a required field. To extend the same example above, if say we have JavaScript to copy address for CC from other fields when you check address is same check box and if we have required validators on the CC address fields, you may notice when you check (which copies) and uncheck (which clears) the our error indicator appears on those fields. To overcome, just call the same method like above in your copy or clear javascript - it works!
Love coding!
Azure Service Fabric 6.5 Refresh Release
7 years ago
2 comments:
thanks a lot buddy.... :)
it was very helpful for me. I search a lot in net but didn't get a better and simple solution that you have given.
thanks again...
instead of
ValidatorEnable(document.getElementById('<%=rqrdtxtCCNumber.UniqueID.ToString().Replace("$", "_")%>'), true);
use
ValidatorEnable(document.getElementById('<%=rqrdtxtCCNumber.ClientID%>'), true);
Post a Comment