我试图使用的CustomValidator来验证DIV表格,然后将其关闭,如果没有验证错误。下面是我的code,我不能让我的自定义验证工作,当我点击提交,什么验证,不知道什么是错的。请指教。谢谢你。
函数validateRedemptionDialog(SRC,参数){ VAR RDATE =的document.getElementById('<%= uitxtRedemptionDate.ClientID%GT;')值。 如果(RDATE ==){ args.IsValid = FALSE; 返回; } args.IsValid = TRUE; }功能closeRedemptionDialog(){ $('#dialog_Active_Redemption_confirm')对话框(亲密); }< DIV ID =dialog_Active_Redemption_confirm的风格=显示:无> < DIV CLASS =section_body> < DIV CLASS =section_body_content> < DIV CLASS =行> < ASP:标签=服务器ID =uilblRedemptionDate文本=<%$资源:MembersNContactsManagerResources,uigrdhdrTransDate%GT; 的CssClass =标签> < / ASP:标签> < ASP:文本框ID =uitxtRedemptionDate=服务器的CssClass =文本的DatePicker风格=宽度:120像素; 保证金右:2px的;> < / ASP:文本框> < ASP:的CustomValidator ID =ctvtxtCamDateEnd=服务器ClientValidationFunction =validateRedemptionDialog 的ControlToValidate =uitxtRedemptionDate的ErrorMessage ='< IMG SRC =../图像/图标/ error.png的风格=垂直对齐:中间的/> XXX! 字体名称=宋体FONT-SIZE =X-小SetFocusOnError =真显示=动态/> < / DIV> < DIV CLASS =行> < ASP:标签=服务器ID =uilblRedemptionAmountSpent文本=<%$资源:MembersNContactsManagerResources,uilblRedemptionAmountSpent%GT; 的CssClass =标签> < / ASP:标签> < ASP:文本框ID =uitxtRedemptionAmountSpent=服务器风格=宽度:120像素;> < / ASP:文本框> < / DIV> < DIV CLASS =行> < UL类=内联的风格=保证金左:137px;填充:的3px;> <立GT;<跨度类=按钮grey_btn> <% - 提交按钮 - %GT; < ASP:按钮的ID =uibtnRedemption=服务器文本=<%$资源:MembersNContactsManagerResources,uilblSubmit%GT;的OnClientClick =JavaScript的:closeRedemptionDialog();/> <跨度>&安培; NBSP;< / SPAN> < / SPAN>< /李> < / UL> < / DIV> < / DIV> < / DIV> < / DIV>解决方案
验证器将不会验证您的当前配置空文本。设置 ValidateEmptyText 以真正如果需要甚至当用户输入什么它开火。
一个的CustomValidator并不需要有一个的ControlToValidate 。如果你需要在任何情况下验证,你应该把这个属性是空的。
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>解决方案
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.
更多推荐
asp.net +自定义的验证没有验证
发布评论