VB.NET  •  Add Login Code to the Click Event

Listing 5. This code shows the Login button's Click event code. When the user clicks on the Login button, it's time for the validation to occur. The event handler doesn't (and shouldn't) know the details about the Validate method—only that there is such a method.

Private Sub btnLogin_Click(ByVal sender As _
   System.Object, ByVal e As System.EventArgs) _
   Handles btnLogin.Click
   'Put user code to initialize the page here
   Dim objUser As New SecurityUser()

   objUser.Name = txtUserID.Text
   objUser.Password = txtPassword.Text
   If objUser.Validate Then
      'Store off user info for later use
      Session("CurrentUser") = objUser
      Session("UserName") = "Guest"

      ' Now have .NET send the user back to the
      ' requesting page
      MobileFormsAuthentication. _
         RedirectFromLoginPage _
         (objUser.Name, False)
   Else
      lblInvalidLogin.Visible = True
   End If
End Sub