c# - Prevent Range Validator to show error message with regular expression validator in asp.net -
i have 1 textbox id txtnumofbooks
validating against following 3 validators:
<asp:requiredfieldvalidator id="requiredfieldvalidator1" runat="server" controltovalidate="txtnumofbooks" display="dynamic" errormessage="please enter number of books" setfocusonerror="true" cssclass="style4" validationgroup="createvac"> </asp:requiredfieldvalidator> <asp:regularexpressionvalidator id="regularexpressionvalidator2" runat="server" controltovalidate="txtnumofbooks" display="dynamic" errormessage="please enter valid number" validationexpression="[0-9]\d*[0-9]" cssclass="style4" validationgroup="createvac"> </asp:regularexpressionvalidator> <asp:rangevalidator id="rangevalidator1" runat="server" controltovalidate="txtnumofbooks" display="dynamic" errormessage="number of books in book shelf should in range 1-100" maximumvalue="100" minimumvalue="1" type="integer" cssclass="style4" validationgroup="createvac"> </asp:rangevalidator>
however,whenever entered characters in textbox both messages:
please enter valid number number of books in book shelf should in range 1-100
are displayed.how can avoid range validator showing error message regular expression validator message?
finally, found answer.there need add javascript function removes unneccessary range validator message.the function is:
function clearrangemessageposition() { if (document.getelementbyid('<%=regularexpressionvalidator1.clientid %>').getattribute('isvalid') != true.tostring()) { document.getelementbyid('<%=rangevalidator1.clientid %>').innertext = ""; } else { document.getelementbyid('<%=rangevalidator1.clientid %>').innertext = "please enter number of books in range 1-100"; } }
Comments
Post a Comment