AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 How To Validate CheckBox within MasterPage Through CustomValidator Control?
Posted by Moderator1 on  2/3/2009 1:48:19 AM 7178 Views
Step 1: Add CustomValidator control, set its ClientValidationFunction property and set an ErrorMessage.

<asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="fnCheckAgree"
ErrorMessage="You Must Choose This CheckBox" Display="Dynamic"></asp:CustomValidator>

Step 2: Add JavaScript Code as follows,

<script>
function fnCheckAgree(source,arguments)
{
if (document.getElementById('<%=CheckBox1.ClientID%>').checked==true)
arguments.IsValid=true;
else
arguments.IsValid=false;
}
</script>

NOTE: The above JavaScript code contains an inline block of Asp.Net code to retrieve the ClientID of the CheckBox control.

Post New Tips/Tricks View all Tips/Tricks

Featured Resources:
Programmers Heaven C# School Book - Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition - Free 207 Page Preview!
A compilation of the best solutions provided to common PHP questions.
100% Free Subscription until Stock lost.View complete list.
Sponsored by