I am dealing with a checkbox containing a javascript function that triggers onclick to toggle the visibility of a div. Within this div, there is a textbox with a CompareValidator that validates the input as a Double. The issue arises when the checkbox is checked and the div is shown, causing the CompareValidator to validate an empty textbox, resulting in an error message display by default. Is there a way to modify the CompareValidator so that it only validates when the text in the textbox is not null or an empty string after the checkbox has made the div visible? Thank you for your help.
<table id="tblLabTests" class="fullWidth dataEntryTableTop" runat="server" visible="false" clientidmode="Static">
<tr id="trL_FBC" clientidmode="static">
<td>
<asp:CheckBox ID="chkL_FBC" runat="server" clientidmode="static" />
<asp:Label AssociatedControlID="chkL_FBC" ID="lblL_FBC" runat="server" Text="FBC" />
</td>
<td>
<div id="divFBC" runat="server" clientidmode="static">
<table id="tblFBC" class="fullWidth noBorder" runat="server" clientidmode="static">
<tr>
<td>
<asp:Label ID="lblPlateletCount" runat="server" Text="Platelet Count" />
</td>
<td>
<asp:TextBox ID="txtPlateletCount" runat="server" MaxLength="4" CssClass="width50" />
<asp:Label ID="Label10" runat="server">*10<sup>9</sup>/L</asp:Label><br />
<asp:CompareValidator ClientIDMode="Static" CssClass="cvRed" runat="server" id="CompareValidator1" ControlToValidate="txtPlateletCount" Type="Double" ErrorMessage="Must be a number" Display="Dynamic" Operator="DataTypeCheck" />
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
function fbcUpdate() {
var checked = $('#chkL_FBC').is(':checked');
if (checked) {
$('#divFBC').css('display', '');
}
else {
$('#divFBC').css('display', 'none');
}
}