我目前正在 vb.net 中處理一個專案,但我無法讓我的自定義驗證器在 radcombobox 上作業。當我運行我的應用程式并測驗驗證時,它沒有被呼叫,導致我的應用程式中斷。我不是在研究客戶端驗證,只是在服務器端。下面是我一直在使用的代碼。
Aspx代碼
<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>
服務端代碼
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
任何幫助將非常感激。
uj5u.com熱心網友回復:
我設法讓服務器端自定義驗證作業。為此,我創建了一個驗證組
<asp:ValidationSummary ID="ValidationSummaryEditItem" runat="server" ValidationGroup="TimeZone" />
并設定
CausesValidation="true"
在編輯按鈕上并添加
ValidationGroup="TimeZone"
到編輯按鈕和自定義驗證器
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/338100.html
