code_junkie

Problem rendering error text from Custom Validator

Nov 13th, 2011
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. Private Sub btnWindowsLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnWindowsLogin.Click
  2. Dim username As String = txtNetworkID.Text.Trim
  3. Dim password As String = txtPassword.Text
  4.  
  5. If username.IsEmpty Then
  6. ErrorSummary.AddError("Please enter your NT Login", "WindowsLogin", Page)
  7. End If
  8. If password.IsEmpty Then
  9. ErrorSummary.AddError("Please enter your password", "WindowsLogin", Page)
  10. End If
  11. If Page.IsValid Then
  12. If Not AuthenticationService.ValidateActiveDirectoryLogin(username, password) Then
  13. ErrorSummary.AddError("The username or password you entered is incorrect", Page)
  14. ElseIf Not UserService.WindowsLoginExists(username) Then
  15. ErrorSummary.AddError("The NT Login entered is not associated with an account in the application", Page)
  16. Else
  17. 'Get the user and validate the role, if the user is active, etc...
  18.  
  19. End If
  20. End If
  21. End Sub
  22.  
  23. Public Class ErrorSummary
  24. Inherits BaseValidator
  25.  
  26. Public Sub New(ByVal message As String, ByVal validationGroup As String)
  27. MyBase.Text = message
  28. MyBase.ValidationGroup = validationGroup
  29. MyBase.IsValid = False
  30. End Sub
  31.  
  32. Public Sub New(ByVal message As String)
  33. Me.New(message, String.Empty)
  34. End Sub
  35.  
  36. Public Shared Sub AddError(ByVal message As String, ByVal page As Page)
  37. AddError(message, String.Empty, page)
  38. End Sub
  39.  
  40. Public Shared Sub AddError(ByVal message As String, ByVal validationgroup As String, ByVal page As Page)
  41. Dim objError As New ErrorSummary(message, validationgroup)
  42. page.Validators.Add(objError)
  43. End Sub
  44.  
  45. Protected Overrides Function EvaluateIsValid() As Boolean
  46. Return False
  47. End Function
  48.  
  49. End Class
Add Comment
Please, Sign In to add comment