<abc:CustomValidator ID="uxLinesValidator" runat="server" ClientValidationFunction="validateLines" OnServerValidate="uxLinesValidator_Validate" ErrorMessage="Exactly one primary line must be specified." />
function validateLines(sender, e) { e.IsValid = ($("span#uxLinesGridViewSpan>div>table").length > 0); }
Protected Sub uxLinesValidator_Validate(ByVal source As Object, ByVal args As ServerValidateEventArgs) Dim primaryRows As Integer = 0 For Each gvRow As GridViewRow In uxLinesGridView.Rows If gvRow.RowType = DataControlRowType.DataRow Then Dim uxPrimaryCheckBox As CheckBox = _ CType(gvRow.FindControl("uxPrimaryCheckBox"), CheckBox) If uxPrimaryCheckBox IsNot Nothing AndAlso uxPrimaryCheckBox.Checked Then primaryRows += 1 End If End If Next args.IsValid = (primaryRows = 1) End Sub
Imports Microsoft.VisualBasic Namespace AcmeBroomCompany Public Class CustomValidator Inherits System.Web.UI.WebControls.CustomValidator Private _entity As String Public Sub New() Display = ValidatorDisplay.Dynamic Text = "" SetFocusOnError = True EnableClientScript = False Dim img As Image = New Image() img.ImageUrl = "~/images/Exclamation.png" Me.Controls.Add(img) _entity = "" End Sub Public Property Entity() As String Get Return _entity End Get Set(ByVal value As String) _entity = value End Set End Property Public Overloads Property ClientValidationFunction() As String Get Return MyBase.ClientValidationFunction End Get Set(ByVal value As String) If value.Length > 0 Then MyBase.ClientValidationFunction = value Me.EnableClientScript = True Else MyBase.ClientValidationFunction = "" Me.EnableClientScript = False End If End Set End Property Public Overloads Property ErrorMessage() As String Get Return MyBase.ErrorMessage End Get Set(ByVal value as String) MyBase.ErrorMessage = value MyBase.Text = "<img src='images/Exclamation.PNG' />" End Set End Property End Class End Namespace
TODO