Hi,
I have a detailsview with a radcombobox in the emptytemplate. I want to validate this (I am using load on demand). It seems I need to validate via javascript, but can not get this to working with examples you gave in other forums. I want to prevent the users from typing in an incorrect code in the combo box - one that does not exist and pass validation. Here's what I tried:
The line var text = element.get_test() throws an error that the method is not valid.
Here's a snippet of the HTML page:
Thanks in advance for your help.
Gary
I have a detailsview with a radcombobox in the emptytemplate. I want to validate this (I am using load on demand). It seems I need to validate via javascript, but can not get this to working with examples you gave in other forums. I want to prevent the users from typing in an incorrect code in the combo box - one that does not exist and pass validation. Here's what I tried:
| function validateCombo(source, args) |
| { |
| args.IsValid = false; |
| var elements = document.getElementsByTagName('*'); |
| var count = elements.length; |
| var targetId = 'rcbCAGE'; |
| var i; |
| for (i = 0; i < count; i++) { |
| var element = elements[i]; |
| var pos = element.id.indexOf(targetId); |
| if(pos >= 0 && element.type == 'text' ) { |
| //found rad combo element |
| var text = element.get_text(); |
| var item = element.findItemByText(text); |
| if (item) |
| { |
| args.IsValid = true; |
| } |
| } |
| } |
The line var text = element.get_test() throws an error that the method is not valid.
Here's a snippet of the HTML page:
| <asp:DetailsView ID="dvCageCode" DataKeyNames="CageCodeID" runat="server" AutoGenerateRows="False" |
| DataSourceID="CAGEData" Height="50px" Width="337px" |
| OnItemCommand="dvCageCode_ItemCommand" |
| OnItemCreated="dvCageCode_ItemCreated" |
| ondatabound="dvCageCode_DataBound" |
| onitemupdating="dvCageCode_ItemUpdating" |
| oniteminserting="dvCageCode_ItemInserting" |
| OnItemInserted="OnItemInserted" |
| OnItemUpdated="OnItemUpdated" |
| CellPadding="10" CommandRowStyle-Height="50px" |
| CommandRowStyle-VerticalAlign="Middle"> |
| <CommandRowStyle VerticalAlign="Middle" Height="50px"></CommandRowStyle> |
| <EmptyDataTemplate> |
| <table> |
| <tr> |
| <td nowrap="nowrap">Cage Code:</td> |
| <td nowrap="nowrap"> |
| <telerik:RadComboBox ID="rcbCAGE" runat="server" EnableLoadOnDemand="true" MarkFirstMatch="false" |
| OnItemsRequested="rcb_ItemsRequested" OnSelectedIndexChanged="rcb_SelectedIndexChanged" AutoPostBack="true" ShowMoreResultsBox="true" Skin="Mac" /> |
| <asp:Label ID="lblCageRequired" runat="server" Text="*" CssClass="RequiredMark" Visible="true" /> |
| <asp:RequiredFieldValidator ID="rValCageCode" runat="server" Text="Please select a CAGE Code" InitialValue="" ControlToValidate="rcbCAGE" ErrorMessage="*" Enabled="true" SetFocusOnError="true" ValidationGroup="Submit" Display="Dynamic" /> |
| <asp:CustomValidator ID="cValCAGE" |
| runat="server" |
| ControlToValidate="rcbCAGE" |
| ValidateEmptyText="True" |
| ClientValidationFunction="validateCombo" |
| ErrorMessage="Please select a CAGE Code from the list"> |
| </asp:CustomValidator> |
| </td> |
| </tr> |
| </table> |
| </EmptyDataTemplate> |
Thanks in advance for your help.
Gary