asp.net - How do you clear a CustomValidator Error on a Button click event? -
i have composite user control entering dates:
the customvalidator include server sided validation code. error message cleared via client sided script if user alters teh date value in way. this, included following code hook 2 drop downs , year text box validation control:
<script type="text/javascript"> validatorhookupcontrolid("<%= ddlmonth.clientid%>", document.getelementbyid("<%= customvalidator1.clientid%>")); validatorhookupcontrolid("<%= ddldate.clientid%>", document.getelementbyid("<%= customvalidator1.clientid%>")); validatorhookupcontrolid("<%= txtyear.clientid%>", document.getelementbyid("<%= customvalidator1.clientid%>")); </script>
however, validation error cleared when user clicks clear button. when user clicks clear button, other 3 controls reset. avoid post back, clear button regular html button onclick event resets 3 controls. unfortunately, validatorhookupcontrolid method not seem work on html controls, thought change html button asp button , hookup control instead. however, cannot seem eliminate postback functionality associated default asp button control. tried set usesubmitbehavior false, still submits. tried return false in btnclear_onclick client code, code sent browser included dopostback call after call.
btnclear.attributes.add("onclick", "btnclear_onclick();")
instead of adding onclick code, tried overwriting it, dopostback code still included in final code sent browser.
what have clear button clear customvalidator error when clicked , avoid postback?
btnclear.attributes.item("onclick") = "btnclear_onclick();"
try adding return false;
@ end of onclick
call. should prevent default behavior (in case submit).
btnclear.attributes.add("onclick", "btnclear_onclick(); return false;")
Comments
Post a Comment