Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
Add your own
alternative version

Exploring ASP.NET Validators

, 9 Apr 2010 CPOL
This article digs deep into ASP.NET validators and discusses a few case studies which may be a boon for any project
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="caseSStudy2.aspx.cs" Inherits="caseSStudy2" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
<script language="javascript" type="text/javascript">

function openpopup(lblId,tbId)
    var url="popup.aspx?lblid="+lblId +"&textboxId="+ tbId ;, "OpenWindowChild",'left=70,top=0,width=250, height=150');
function validateCost(sender, args)
    var tbIds= document.getElementById('hdnTextBoxIds').value;
    var arrIds=tbIds.split(',');
    var validationControl= document.getElementById('gridValidator');
    for(var i=0;i<arrIds.length-1;i++)
        var curObj=document.getElementById(arrIds[i]);
        if(curObj.value == 0)
              ValidatorHookupControl(curObj, validationControl);
              sender.errormessage="<b>Invalid field</b><br />Please enter the cost." ;   
              args.IsValid = false; 
    if(args.IsValid ==false)
        ShowValidationCallout(validationControl, arrIds[i]);

function ShowValidationCallout(validationControl, elementClientID)
        if(validationControl.ValidatorCalloutBehavior != null)
            if(validationControl.ValidatorCalloutBehavior._popupBehavior != null)
            if(validationControl.ValidatorCalloutBehavior._errorMessageCell !=null)
                validationControl.ValidatorCalloutBehavior._errorMessageCell.innerHTML = validationControl.errormessage;
    <title>Untitled Page</title>
    <form id="form1" runat="server">
     <asp:ScriptManager ID="ScriptManager1" runat="server">
    <table border="1px" width="50%" style="font-family:Verdana">
            <td width="50%" style="font-weight:bolder">
            <td width="50%" style="font-weight:bolder">
        <asp:Repeater ID="rpUpdateAdpdetails" runat="server" OnItemDataBound="rpUpdateAdpdetails_ItemDataBound">
                <tr style="border-top: 1px solid #E8E8E8">
                    <td style="border-top: 1px solid #E8E8E8">
                        <asp:Label ID="lblName" runat="server" Text="Label"></asp:Label>
                    <td style="border-top: 1px solid #E8E8E8">
                        $<asp:Label ID="lblCost" runat="server" Text="Label"></asp:Label>
                        <!--This is the textbox on the grid validator will be attached -->
                        <asp:TextBox ID="txtCost" runat="server" Width="0px" Height="0px"></asp:TextBox>
     <!-- This custom validator is going to attached dynamically on all the texboxes-->
        <asp:CustomValidator ID="gridValidator" runat="server" ClientValidationFunction="validateCost" ></asp:CustomValidator>
        <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" TargetControlID="gridValidator">
        <asp:Button ID="Button1" runat="server" Text="Submit" />
        <asp:HiddenField ID="hdnTextBoxIds" runat="server" />
        <%--<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
          <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" runat="server" TargetControlID="RequiredFieldValidator1">
        <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator" ControlToValidate="TextBox1" ClientValidationFunction="validatetextbox"></asp:CustomValidator>
         <cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender3" runat="server" TargetControlID="CustomValidator1">
        <asp:Button ID="Button1" runat="server" Text="Button" />--%>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
India India
Brij is a 3-times Microsoft MVP in ASP.NET/IIS Category and a passionate .NET developer. More than 6 years of experience in IT field, currently serving a MNC as a Tech Lead/Architect.
He is a very passionate .NET developer and have expertise over Web technologies like ASP.NET 2.0/3.5/4.0, jQuery, JSON, Javascript, IIS and related technologies. He is also a Exchange Server (EWS) Specialist. He has great experience in design patterns and N-Tier Architecture.
He is also certified as Microsoft Certified Technologies Specialist-ASP.NET and Microsoft Certified Technologies Specialist-WCF in .NET 4.0. He has also received several awards at various forums and his various articles got listed as "Article of the day" at ASP.NET Microsoft Official Website
He has done MCA from NIT Durgapur and completed his graduation from Lucknow University.
Learning new technologies and sharing knowledge excites him most. Blogging, solving problems at various forums, helping people, keeps him busy entire day.

Visit his Blog: Brij's arena of .NET
Area of Expertise :
C#, ASP.NET 2.0,3.5,4.0, AJAX, JQuery, JSON, XML, XSLT, ADO.Net, WCF, Active Directory, Exchange Server 2007 (EWS), Java script, Web Services ,Win services, DotnetNuke, WSS 3.0,Sharepoint Designer, SQL Server 2000/2005/2008
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 10 Apr 2010
Article Copyright 2010 by Brij
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid