I have a situation where i'd like to create custom validation for a combobox, but i'm at a loss as to how to write the client validation logic. I'm basically looking to create the equivalent of a requiredfieldvalidator, but instead of showing an error message somewhere on the page, i would like to modify the appearance of the combox itself using CSS. i have this working via server side validation by doing the following:
Anytime i want to validate a combobox i place something like this on my page
<asp:Label ID="lblError1" runat="server" Visible="false">
<style type="text/css">
#<%=rcbFolders.UniqueID.Replace("$","_")%>.RadComboBox_test table {
background-color: RED;
}
#<%=rcbFolders.UniqueID.Replace("$","_")%>.RadComboBox_test .rcbInputCell, #<%=rcbFolders.UniqueID.Replace("$","_")%>.RadComboBox_test .rcbArrowCell {
background-color: red;
}
</style>
</asp:Label>
and on the server side i check to see if any items are selected and if not i change the label to visible.
This works because of the fact that the styles are declared inline in the page and take precedence over styles declared in my skin stylesheets at the top of the page. Including the uniqueid in the css assures me that the css for just the control that i'm validating is updated.
This solution is ok, it is effective, but it's kind of awkward, especially on pages that have other requiredfieldvalidators that include client side validation. The user receives visual feedback immediately for the other client-side validated fields, but they have to wait till all those checks pass and the postback to the server is made before they can get the visual feedback on the combobox selection. I think i could hack my way into using a custom validator to validate the combobox selection on the client, but i'm not sure how to go about achieving the actual "notification" that we're after by updating the color of the control on error.
Any ideas about how this could be accomplished?
Thanks!
-Mark