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 3534 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:
The JavaScript Anthology: 101 Essential Tips, Tricks & Hacks - Free 158 Page Preview
Get the most out of this complete question-and-answer book on JavaScript.
Simply SQL - Free 111 Page Preview!
Simply SQL is a practical step-by-step guide to writing SQL.
100% Free Subscription until Stock lost.View complete list.
Sponsored by