Solved

Validator issue in ASP.net

Posted on 2006-11-07
4
451 Views
Last Modified: 2012-08-13
I have a userControl as shown below. I am using the same usercontrol twice in one of my ASPX pages. How do I add requiredFieldValidator or CustomValidator in my ASPX page where I am using the usercontrol instead of adding in the usercontrol itself.

When I try to add it in my aspx page I am getting this error

Control 'calStart' referenced by the ControlToValidate property of 'cvCalendar' cannot be validated.


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Calendar.ascx.cs" Inherits="z360.Forms.modules.Utilities.zeewiseCalendar" %>

<table cellpadding=2 cellspacing=2>
<tr>
    <td><asp:TextBox ID="txtCalendar" Width="100" runat=server></asp:TextBox></td>
    <td><a id="hypCalendar" runat=server><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the Date"></a><asp:Label ID="Label1" runat=server Text="*" ForeColor=red Visible=false ></asp:Label></td>    
</tr>

</table>


And when I register and user Control twice in my ASPX page as shown below:

<%@ Register TagPrefix="zw" TagName="Calendar" Src=”Calendar.ascx" %>

Start Date/Time<zw:Calendar ID="calStart" runat=server />
Start Date/Time<zw:Calendar ID="calEnd" runat=server />

And when I add a customFieldvalidator as shown below it is throwing out errors:
<asp:CustomValidator ID="cvCalendar" ControlToValidate="calStart" runat=server OnServerValidate="calendarValidate"></asp:CustomValidator>
0
Comment
Question by:rowmark
4 Comments
 
LVL 10

Expert Comment

by:eguilherme
ID: 17895060
havent tried/tested but..

when u put a user control on the page, all of your the controls of the userControl will be renamed like this:

original name:

TextBox1

suppose ur userControl Id at the main page is UserControl1

so ur TextBox1 will be then

UserControl1_TextBox1

so i suppose u gotta make the control to validade to be like that [UserControlID]_[ControlIdToValidade]

not sure tho =/
0
 

Author Comment

by:rowmark
ID: 17895540
No. it doesnt work
0
 
LVL 13

Accepted Solution

by:
jeebukarthikeyan earned 500 total points
ID: 17896251
hi,
In order to be referenced by a validation control, a control must have a validation property. All controls that can be validated have a ValidationPropertyAttribute, which indicates which property should be read for the purposes of validation. If you write your own control, you can make it take part in validation by providing one of these attributes to specify which property to use.

b u d d h a
0
 
LVL 3

Expert Comment

by:rugu_16
ID: 17900999
can you provide detailed error message. Also can you try removing one of u r custom control and then see if it throws error. My point is i dont think it metters if you have 2 same control on the page.
0

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

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

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

16 Experts available now in Live!

Get 1:1 Help Now