Hi,
A have the need for a custom validation control to test the comination of a textbox being checked and that a field is not left blank.
It appears that the custom validation event does not fire when the ControlToValidate is left blank.
I cant use the RequiredFieldValidator because it does not allow me to test the checkbox.
I guess I could put in a hidden textbox and use it as the ControlToValidate with some content just to fire the client event.
And then test the correct field length throught javascript ignoring the args.Value of the validator.
BUT this seems like a poor method.
Doen anyone know the correct way to do this.
An simplified example of the situation is below.
This ignores the checkbox situation but if the code is run you will see that the client side event only fires when something is in the textbox.
Code:
<HTML>
<HEAD>
<script language="JavaScript">
function validateNumber(oSrc, args) {
alert('Boo');
args.IsValid = (args.Value.length > 3);
}
</script>
</HEAD>
<body>
<form runat="server" ID="Form1">
<p>
Number:
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator id="CustomValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="The input must have at least 4 characters"
ClientValidationFunction="validateNumber"></asp:CustomValidator>
</p>
<p>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</p>
<p>
<asp:Label id="Label1" runat="server"></asp:Label>
</p>
</form>
</body>
</HTML>
Any assistance would be appreciated
======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================