.net - asp.net CustomValidator on multiple controls -


i working page has series of checkboxes @ least 1 box must checked.

the validator fires when click submit button , if no checkboxes checked indicates validation has failed. if check 1 of checkboxes validation message not go away until click submit button again.

if using on control in had specified controltovalidate , fixed validation issue error message goes away immediately.

however in case not setting controltovalidate due need validate several independent controls.

so question can cause re-validation of custom validator? instance add on each checkbox onclick="revalidate()" force validation happen again.

here sample code wrote demonstrate scenario.

<script type="text/javascript">     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>     function isonecheckboxchecked(sender, args) {         if (!$('[id$=checkbox1]').attr('checked') &&     !$('[id$=checkbox2]').attr('checked')) {             args.isvalid = false;         }         else {             args.isvalid = true;         }     } </script>    <asp:checkbox id="checkbox1" runat="server" /> <br /> <asp:checkbox id="checkbox2" runat="server" /> <br /> <asp:customvalidator id="customvalidatormustbeoncheckboxchecked"      runat="server" clientvalidationfunction="isonecheckboxchecked"     errormessage="you must select @ least 1 checkbox option"      onservervalidate="customvalidatormustbeoncheckboxchecked_servervalidate" /> <br /> <br /> <asp:button id="buttonsubmit" runat="server" text="submit" /> 

yes there way of revalidating before commit clicked. asp.net builds 'onblur' event binds control validating in javascript, runs code define in client validation function. running of course clicking checkbox submit again - onblur kicks in when click elsewhere before clearing message. call client validation function on mouseleave or mouseover event before user gets submit button. clear message , keep args.isvalid set correctly, time user clicks submit error message gone , form validates.

for example:

$(".submitbuttondiv").mouseenter(function () {     isonecheckboxchecked(); }); 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -