You can use custom validator to do this task.
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="CustomValidator" ClientValidationFunction="testValid"
ControlToValidate="TextBox1" onservervalidate="CustomValidator1_ServerValidate"
ValidateEmptyText="True">both fields required</asp:CustomValidator>
The ClientValidationFunction
contains the client side javascript function testValid
. so it should look like :
<script type="text/javascript">
function testValid(sender, args) {
....you logic
//set args.IsValid according to your logic
args.IsValid = false;
}
</script>
On server side,
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
//set args.IsValid according to your validation logic.
args.IsValid = false;
}