CustomValidator Control

J

Jim Heavey

Hello, I was am wanting to validate that a user has made a selection from a
dropdownlist control in a datagrid. Is my only option to use a
"CustomValidator Control"? I am not quite sure how to write and attach
JavaScript to the control to ensure the SelectedIndex > -1. Is there a way
to do this in JavaScript (can you provide an example?) or should I just
write Server side validation?

Example:


<asp:DropDownList ID="ddlRating" Runat="server" DataSource="<%#
dtRating %>" DataTextField="Description" DataValueField="Rating" Font-
Size="8"></asp:DropDownList>

<asp:CustomValidator ID="cvlRating" ControlToValidate="ddlrating"
Display="Dynamic" ErrorMessage="Must make a selection">
</asp:CustomValidator>
 
A

AW

Hi,

You should not write any javascript that interferes with a WebControl. This
is because you have NO guarantee on the tags/HTML that will be generated by
the WebControl on a different browser or a different version of ASP.Net.

Consider writing just the server-side validation or using an HtmlControl
(<SELECT runat="server">).
 

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,777
Messages
2,569,604
Members
45,202
Latest member
MikoOslo

Latest Threads

Top