Home > other >  Custom Validation on a RadComboBox is not working
Custom Validation on a RadComboBox is not working

Time:10-25

I am currently working on a project in vb.net and I am having trouble getting my custom validator to work on a radcombobox. When I run my application and test the validation it is not being invoked, causing my application to break. I am not looking into client side validation, just server side. Below is the code I have been using.

Aspx code

<td>
 <telerik:RadComboBox ID="radcomboboxListTimeZone" runat="server" BorderColor="#bbe0ef"
   BorderWidth="2px" Width="400px" MaxHeight="200px" 
   DataSourceID="ObjectDataSourceListTimeZones" 
   DataTextField="DisplayName" DataValueField="StandardName" SelectedValue='<%# 
   Bind("TimeZoneStandardName")%>'>
 </telerik:RadComboBox>

<asp:CustomValidator ID="CustomValidatorTimeZone" runat="server" ErrorMessage="Please select a 
   valid Time Zone Standard Name" ControlToValidate="radcomboboxListTimeZone" 
   OnServerValidate="CustomValidatorListTimeZone_ServerValidate">•</asp:CustomValidator>
</td>

Server side code

Protected Sub CustomValidatorListTimeZone_ServerValidate(ByVal source As Object, ByVal args As 
 ServerValidateEventArgs)

    Dim radcomboboxListTimeZone As RadComboBox = 
    CType(FormViewTimeZones.FindControl("radcomboboxListTimeZone"), RadComboBox)
    Dim selectedValue As String = radcomboboxListTimeZone.SelectedValue

    If selectedValue = "Coordinated Universal Time" Then
        args.IsValid = False
    Else
        args.IsValid = True
    End If
End Sub

Any help would be much appreciated.

CodePudding user response:

I managed to get the server side custom validation working. To do this I created a validation group

<asp:ValidationSummary ID="ValidationSummaryEditItem" runat="server" ValidationGroup="TimeZone" />

and set

CausesValidation="true"

on the edit button and added

ValidationGroup="TimeZone"

to both the edit button and the custom validator

  • Related