CustomValidator Control

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
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>
 
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">).
 
Back
Top