wsyeager Posted August 28, 2003 Posted August 28, 2003 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... Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
Moderators Robby Posted August 28, 2003 Moderators Posted August 28, 2003 You need to create a client side script to handle this ( cvRiders) Quote Visit...Bassic Software
wsyeager Posted August 29, 2003 Author Posted August 29, 2003 I just included the validator control inside my itemtemplate.... Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
Moderators Robby Posted August 29, 2003 Moderators Posted August 29, 2003 Did you create a client-side function to be used by the custom validator? Quote Visit...Bassic Software
wsyeager Posted August 30, 2003 Author Posted August 30, 2003 Robby, no I didn't. I didn't get a chance yet to test out the validation, but I am able to display the web page now without a problem. Is there some link or small sample that you could point me to where I can take care of this? Shouldn't the code in my lstRiderValidation event handle this validation? Quote Thanks, Bill Yeager (MCP, BCIP) Microsoft Certified Professional Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer YeagerTech Consulting, Inc.
Moderators Robby Posted August 31, 2003 Moderators Posted August 31, 2003 Here's a small sample I put together. If you enter anything but 100 into the textbox it will not pass validation. Take notice of the client-side script in the head section, and the parameters of the validator.customvalidator_sample.zip Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.