Home > ASP.Net, Javascript > Client Side Validate CheckBoxList using Custom Validator in ASP.Net

Client Side Validate CheckBoxList using Custom Validator in ASP.Net


Hi all,

try this example to Validate CheckBoxList using Custom Validator Control

1) Open VS 2008 and create a new web site and add new web page

2) From ToolBox Drag and Drop CheckBoxList , CustomValidator and Button Control into your page


<script type="text/javascript">
 function ValidateModuleList(source, args) {
 var chkListModules = document.getElementById('<%= chkModuleList.ClientID %>');
 var chkListinputs = chkListModules.getElementsByTagName("input");
 for (var i = 0; i < chkListinputs.length; i++) {
 if (chkListinputs[i].checked) {
 args.IsValid = true;
 return;
 }
 }
 args.IsValid = false;
 }
</script>

<asp:checkboxlist id="chkModuleList" runat="server">
 <asp:listitem text="Red" value="1"></asp:listitem>
 <asp:listitem text="Green" value="2"></asp:listitem>
 <asp:listitem text="Blue" value="3"></asp:listitem>
 <asp:listitem text="Yellow" value="4"></asp:listitem>
 <asp:listitem text="Orange" value="5"></asp:listitem>
 <asp:listitem text="Black" value="6"></asp:listitem>
</asp:checkboxlist>
<asp:customvalidator runat="server" forecolor="Red" id="cvmodulelist"
clientvalidationfunction="ValidateModuleList"
errormessage="Please select atleast one Color."></asp:customvalidator>

Checkboxlist-Validation-CodingFusion

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net, Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: