hello there..
I have a custom validator which validates three text boxes. my code is,
the clientvalidate function is,
the servervalidate function is
now the problem is even when I fill in all the three textboxes.it still gives me the error message to fill in all the boxes and does not submit the page even when all the three boxes are filled.
can somebody please let me know where I am going wrong
thank you
I have a custom validator which validates three text boxes. my code is,
Code:
<table>
<tr>
<td colspan="3">
<asp:CustomValidator ID="CustomValidator_test1" runat="server"
ErrorMessage="The name, date, and score fields must be filled in for other tests"
ClientValidationFunction="ClientValidate_test1" ValidateEmptyText="true"
ValidationGroup="Submit"
onservervalidate="CustomValidator_test1_ServerValidate"
SetFocusOnError="false" Display="Dynamic"></asp:CustomValidator>
</td>
</tr>
<tr>
<td style="border:0">
<asp:TextBox ID="test1" runat="server" Width="100px"></asp:TextBox>
</td>
<td style="border:0" >
<asp:TextBox ID="test1date" runat="server" Width="80px"></asp:TextBox>
</td>
<td style="border:0">
<asp:TextBox ID="test1score" runat="server" Width="80px"></asp:TextBox>
</td>
</tr>
</table>
Code:
function ClientValidate_test1(sender, args) {
var Valtest1 = document.getElementById("<%= test1.ClientID %>");
var Valtest1date = document.getElementById("<%= test1date.ClientID %>");
var Valtest1score = document.getElementById("<%= test1score.ClientID %>");
if ((Valtest1.value == "" && Valtest1date.value == "" && Valtest1score.value != "") ||
(Valtest1.value == "" && Valtest1date.value != "" && Valtest1score.value == "") ||
(Valtest1.value == "" && Valtest1date.value != "" && Valtest1score.value != "") ||
(Valtest1.value != "" && Valtest1date.value == "" && Valtest1score.value == "") ||
(Valtest1.value != "" && Valtest1date.value == "" && Valtest1score.value != "") ||
(Valtest1.value != "" && Valtest1date.value != "" && Valtest1score.value == "")) {
args.IsValid = false;
} else if((Valtest1.value != "" && Valtest1date.value != "" && Valtest1score.value != "") ||
(Valtest1.value == "" && Valtest1date.value == "" && Valtest1score.value == "")){
args.IsValid = true;
}
if (Valtest1.value == "")
document.getElementById("<%= test1.ClientID%>").focus();
else if (Valtest1date.value == "")
document.getElementById("<%= test1date.ClientID%>").focus();
else if (Valtest1score.value == "")
document.getElementById("<%= test1score.ClientID %>").focus();
}
Code:
protected void CustomValidator_test1_ServerValidate(object source, ServerValidateEventArgs args)
{
if ((test1.Text == "" && test1date.Text == "" && test1score.Text != "") || (test1.Text == "" && test1date.Text != "" && test1score.Text == "") ||
(test1.Text != "" && test1date.Text != "" && test1score.Text != "") || (test1.Text != "" && test1date.Text == "" && test1score.Text == "") ||
(test1.Text != "" && test1date.Text == "" && test1score.Text != "") || (test1.Text != "" && test1date.Text != "" && test1score.Text == ""))
{
args.IsValid = false;
}
else if ((test1.Text != "" && test1date.Text != "" && test1score.Text != "") || (test1.Text == "" && test1date.Text == "" && test1score.Text == ""))
{
args.IsValid = true;
}
}
can somebody please let me know where I am going wrong
thank you
Comment