customvalidator problem

B

bill yeager

I'm using the customvalidator in my web page. I get the
following error when I try to run the web page:

Unable to find control id 'lstRider' referenced by
the 'ControlToValidate' property of 'cvRiders'.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and where
it originated in the code.

Exception Details: System.Web.HttpException: Unable to
find control id 'lstRider' referenced by
the 'ControlToValidate' property of 'cvRiders'


Here is part of my HTML that is of concern:
<asp:TemplateColumn HeaderText="Riders">

<ItemTemplate>

<asp:listbox AutoPostBack="False"
BackColor="#ffffff" id="lstRider" runat="server" Rows="1"
DataSource="<%# DsRider1 %>" Enabled="True"
SelectionMode="Multiple" DataTextField="UserName"
DataValueField="UserID" />

</asp:listbox>

</ItemTemplate>

</asp:TemplateColumn>
</asp:datagrid><asp:customvalidator id="cvRiders" style="Z-
INDEX: 104; LEFT: 136px; POSITION: absolute; TOP: 88px"
runat="server"
display="Static"
OnServerValidate="lstRiderValidation" ErrorMessage="Riders
has a maximum selection of 2"
ControlToValidate="lstRider"></asp:customvalidator>


This is what I have in my code-behind:

Sub lstRiderValidation(ByVal source As Object, ByVal
arguments As ServerValidateEventArgs) Handles
cvRiders.ServerValidate

Dim strSelectionArray() As String =
arguments.Value.Split(",")

If strSelectionArray(2).Length > 0 Then 'Max 2
selections
arguments.IsValid = False
Else
arguments.IsValid = True
End If

End Sub

How can I get the customvalidator to recognize my control?
I know it's probably because the control is an
itemtemplate...
 
M

Marina

The ControlToValidate property is not required for custom validators. Leave
it blank.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top