Custom Validator inside a Repeater

Posted on 2009-07-06
Last Modified: 2013-11-07
Hej everyone,

I have a repeater on my ASP.NET page where I am using a customValidator that is valid if two controls in the same RepeaterItem have some particular values.

I am doing only server side validation But CustomValidator validateServerside event is not being truggered even if I call Page.IsValid from C# code.

Please adnice as I am stuck.

Code is as below.
ASPX Page code:



            <b><asp:label runat="server" id="lblRequired" Text="*" ></asp:label></b>



            <asp:Literal ID="litVarName" runat="server"></asp:Literal>



            <asp:TextBox ID="txtVarValue" runat="server"></asp:TextBox>



            <asp:Literal ID="ltrValidationComment" runat="server"></asp:Literal>



            <asp:CustomValidator runat="server" id="requiredVar" ControlToValidate="txtVarValue" OnServerValidate="cusCustom_ServerValidate" errormessage="Variable variable must be given" />


        <asp:HiddenField ID="hidRegexExpression" runat="server" /> 

        <asp:HiddenField ID="hidCampaignVariableId" runat="server" /> 


.cs File Code ... Note this is not being valled at all

protected void cusCustom_ServerValidate(object sender, ServerValidateEventArgs e) {

            // Cast the sender object to a CustomValidator

            CustomValidator vldCustomValidator = (CustomValidator)sender;

            // Find the RepeaterItem, this is the parent object of the CustomValidator

            RepeaterItem rptItem = (RepeaterItem)vldCustomValidator.Parent;

            // Now find the control in the RepeaterItem

            TextBox txtValue = rptItem.FindControl("txtVarValue") as TextBox;

            // something to return

            Label lblRequired = rptItem.FindControl("lblRequired") as Label;

            HiddenField hidRegexExpression = rptItem.FindControl("hidRegexExpression") as HiddenField;

            if(!String.IsNullOrEmpty(hidRegexExpression.Value)) {


                    e.IsValid = false;

                else {

                    e.IsValid = true;



            else {

                e.IsValid = true;



Open in new window

Question by:hussainAbid
1 Comment

Accepted Solution

hussainAbid earned 0 total points
ID: 24784462
The above is actually working Now. The problem was I had to set
ValidateEmptyText="true" and it was not being triggered bcz TextBox value for empty string.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now