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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

11 Experts available now in Live!

Get 1:1 Help Now