使用CustomValidator对asp.net Single

编程入门 行业动态 更新时间:2024-10-11 07:32:18
本文介绍了使用CustomValidator对asp Single-CheckBox进行客户端验证的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用以下代码验证该复选框. 但是它总是返回false. //----------------------------------------

I am trying to validate the check box using the following code. But it is always return false. //----------------------------------------

<script language="javascript" type ="text/javascript" > function checkAgreement(source, args) { var elem = document.getElementById("cbxPDCheque"); if (elem.checked) { args.IsValid = true; } else { args.IsValid = false; } } </script>

//================================================ =====

//=====================================================

<asp:CheckBox ID="cbxPDCheque" runat="server" AutoPostBack="True" Text="PD Cheques" /> <asp:CustomValidator ID="CustomValidator1" runat="server" EnableClientScript ="true" ErrorMessage="Select PD Cheques." ClientValidationFunction ="checkAgreement" >*</asp:CustomValidator> <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True" ShowSummary="False" /> <asp:Button ID="Button1" runat="server" Text="Button" />

//================================================ =======

//=======================================================

推荐答案

我认为您的ClientID错误. I reckon your ClientID is wrong. var elem = document.getElementById("cbxPDCheque");

您需要查看页面的源代码以找出CheckBox的正确ClientID.服务器控件的ID不必与在浏览器中呈现的DOM属性ID相同.

You need to view the source of your page to find out the correct ClientID of the CheckBox. The ID of a server Control is not necessarily the same as the DOM attribute ID that gets rendered in the browser.

var elem = document.getElementById("<%=cbxPDCheque.ClientID%>");

因为控件的ID在渲染后已更改.

Because the ID of the controls is changed after rendering.

更多推荐

使用CustomValidator对asp.net Single

本文发布于:2023-10-30 18:22:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1543644.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:asp   CustomValidator   Single   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!