[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Custom Validator inside a Repeater

Posted on 2009-07-06
1
Medium Priority
?
1,567 Views
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:
 
<ItemTemplate>
        <td>
            <b><asp:label runat="server" id="lblRequired" Text="*" ></asp:label></b>
        </td>
        <td>
            <asp:Literal ID="litVarName" runat="server"></asp:Literal>
        </td>
        <td>
            <asp:TextBox ID="txtVarValue" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:Literal ID="ltrValidationComment" runat="server"></asp:Literal>
        </td>
        <td>
            <asp:CustomValidator runat="server" id="requiredVar" ControlToValidate="txtVarValue" OnServerValidate="cusCustom_ServerValidate" errormessage="Variable variable must be given" />
        </td>
        <asp:HiddenField ID="hidRegexExpression" runat="server" /> 
        <asp:HiddenField ID="hidCampaignVariableId" runat="server" /> 
    </ItemTemplate>
 
.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)) {
                if(String.IsNullOrEmpty(txtValue.Text))
                    e.IsValid = false;
                else {
                    e.IsValid = true;
                }
            }
            else {
                e.IsValid = true;
            }
        }

Open in new window

0
Comment
Question by:hussainAbid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
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.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

656 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