下面是我的JavaScript代码,但是当我尝试使用它时,它不起作用,我不知道为什么,有人可以帮助我。谢谢!
<script type="text/javascript" >
function FatherClientValidate(oSrc, args) {
var textBox = document.getElementById('<%=FatherName.ClientID%>');
if (textBox.value != '') {
var ctrlid = oSrc.id;
var validatorid = document.getElementById(ctrlid);
ctrlid = validatorid.controltovalidate;
document.getElementById(ctrlid).style.backgroundColor = "#ff0000";
args.IsValid = true;
}
else {
var ctrlid = oSrc.id;
var validatorid = document.getElementById(ctrlid);
ctrlid = validatorid.controltovalidate;
document.getElementById(ctrlid).style.backgroundColor = "White";
args.IsValid = false;
}
}
</script>
这是我的CustomValidator代码
<asp:requiredfieldvalidator Display="Dynamic" id="Requiredfieldvalidator25" runat="server" ForeColor="Red" errormessage="*Required" controltovalidate="FDateOfBirth" >
<asp:CustomValidator runat="server" ID="CustomValidator2" ControlToValidate="FDateOfBirth" ClientValidationFunction="FatherClientValidate" ValidateEmptyText="true" EnableClientScript="true"></asp:CustomValidator>
</asp:requiredfieldvalidator>