Solved

Validator issue in ASP.net

Posted on 2006-11-07
4
450 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

17 Experts available now in Live!

Get 1:1 Help Now