Reputation: 2473
I am trying to use a customvalidator to validate a DIV form and then close it if there is no validation errors. Below is my code, I can't get my custom validator to work, when I click submit, nothing validates, not sure what's wrong. Please advice. Thanks.
function validateRedemptionDialog(src, args) {
var rDate = document.getElementById('<%=uitxtRedemptionDate.ClientID%>').value;
if (rDate == "") {
args.IsValid = false;
return;
}
args.IsValid = true;
}
function closeRedemptionDialog() {
$('#dialog_Active_Redemption_confirm').dialog('close');
}
<div id="dialog_Active_Redemption_confirm" style="display: none">
<div class="section_body">
<div class="section_body_content">
<div class="row">
<asp:Label runat="server" ID="uilblRedemptionDate" Text="<%$ Resources:MembersNContactsManagerResources, uigrdhdrTransDate %>"
CssClass="label">
</asp:Label>
<asp:TextBox ID="uitxtRedemptionDate" runat="server" CssClass="text DatePicker" Style="width: 120px;
margin-right: 2px;">
</asp:TextBox>
<asp:CustomValidator ID="ctvtxtCamDateEnd" runat="server" ClientValidationFunction="validateRedemptionDialog"
ControlToValidate="uitxtRedemptionDate" ErrorMessage='<img src="../Images/icons/error.png" style="vertical-align:middle"/> XXX!'
Font-Names="arial" Font-Size="X-Small" SetFocusOnError="True" Display="Dynamic" />
</div>
<div class="row">
<asp:Label runat="server" ID="uilblRedemptionAmountSpent" Text="<%$ Resources:MembersNContactsManagerResources, uilblRedemptionAmountSpent %>"
CssClass="label">
</asp:Label>
<asp:TextBox ID="uitxtRedemptionAmountSpent" runat="server" Style="width: 120px;">
</asp:TextBox>
</div>
<div class="row">
<ul class="inline" style="margin-left: 137px; padding: 3px;">
<li><span class="button grey_btn">
<%--Submit button--%>
<asp:Button ID="uibtnRedemption" runat="server" Text="<%$ Resources : MembersNContactsManagerResources, uilblSubmit %>" OnClientClick="javascript:closeRedemptionDialog();"/>
<span> </span> </span></li>
</ul>
</div>
</div>
</div>
</div>
Upvotes: 1
Views: 448
Reputation: 460288
The validator will not validate empty text with your current configuration.
Set ValidateEmptyText to true
if you need it to fire even when the user has entered nothing.
A CustomValidator does not need to have a ControlToValidate. If you need to validate in any case, you should leave that property empty.
Upvotes: 3