I have a form that requires the input of text (such as name, email) and the input of numbers as well (such as salary). For fields that require a number, I need to use a custom validator to verify that the input was indeed a number and not random text. At the same time, when the submit button is pressed, I also need to submit the form data to a database.
The problem I'm having is that I can not get my server side code (to submit to database) to work in conjunction with the custom validator (which uses javascript). In other words, when the "OnClick" event is specified for the submit button, the custom validator does not fire. When the "OnClick" event is left empty for the button, the custom validator does fire. How do I fix this?
The problem I'm having is that I can not get my server side code (to submit to database) to work in conjunction with the custom validator (which uses javascript). In other words, when the "OnClick" event is specified for the submit button, the custom validator does not fire. When the "OnClick" event is left empty for the button, the custom validator does fire. How do I fix this?
Code:
<script type="text/javascript" language="jscript">
function CheckInt(source, args){
if (isNaN(document.getElementById("<%=txtSalary.ClientID%>").value)) {
alert('Please enter valid number'); args.IsValid = false;
}
else {
args.IsValid = true;
}
}
</script>
Code:
<tr>
<td><b>Salary:</b></td>
<td>
<asp:TextBox ID="txtSalary" runat="server" Width="210px" ValidationGroup="qualify"></asp:TextBox>
</td>
<td>
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="txtSalary" ErrorMessage="Valid number required" ValidationGroup="qualify" ClientValidationFunction="IntCheck" Display="Dynamic"
Font-Bold="True" ForeColor="Red">
</asp:CustomValidator>
</td>
</tr>
<tr>
<td></td>
<td style="padding-top:10px;">
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
ValidationGroup="qualify" onclick="btnSubmit_Click" /></td>
</tr>