Feb 21, 2008

Validate Input Values With Message List

Private Function ValidateInputValues(ByVal control As Control, ByVal pageType As PageType) As ArrayList
Dim messageList As ArrayList = New ArrayList()
DataFormat.SetDateSeparator("/")
If (pageType <> PageType.Search) Then ' Add/Edit Validation
Dim fullName As TextBox = TryCast(control.FindControl("fullName"), TextBox)
If (fullName IsNot Nothing) Then
If (Not DataFormat.CheckString(fullName.Text)) Then
messageList.Add("Invalid Value (String): fullName")
End If
End If
Dim phoneNumber As TextBox = TryCast(control.FindControl("phoneNumber"), TextBox)
If (phoneNumber IsNot Nothing) Then
If (Not DataFormat.CheckInt32(phoneNumber.Text)) Then
messageList.Add("Invalid Value (Int32): Phone Number")
End If
End If
End If
Return IIf(messageList.Count = 0, Nothing, messageList)
End Function


' Powerful TIPs !
Dim source As WebControl = TryCast(sender, WebControl)







No comments:

Post a Comment