0

How do I reference the values in a textbox in a separate VB module.

In my login.aspx.vb module I have

Public Class login
    Inherits System.Web.UI.Page

    Private _inlineAssignHelper As String

    Protected Sub LoginButton(ByVal sender As Object, 
                              ByVal e As System.EventArgs) Handles Button1.Click

        Dim UserLogin As New String("")
        Dim UserPass As New String("")

        UserLogin = username.Text
        UserPass = password.Text

        Dim SecurityUser As New SecurityUser(UserLogin)
        Dim SecurityPass As New SecurityPass(UserPass)
    End Sub

End Class

Now in my separate Security.vb module I want to check that the values aren't null and send them to the database but I can't appear to reference the values correctly to do this. Can anyone help?

Public Sub securityCheck(UserLogin, UserPass)

    Dim securityCheck As Array()
    ' Dim User As String = TheNRLPredator.login.LoginButton(UserLogin)

    If (String.IsNullOrEmpty(TheNRLPredator.login.(UserLogin) _
       && String.IsNullOrEmpty(TheNRLPredator.login.(UserLogin) =True) Then
        MsgBox("You need to enter a Username and Password")
    Else
        'send to database to check.
    End If

End Sub

1 Answer 1

1

Is the securityCheck sub in a class? I would change the code a little, like this:

Public Class SecurityChecker

    ' Note the Shared. PS: I would also rename "securityCheck()" to "Validate()":
    Public Shared Function Validate(UserLogin, UserPass) As Bool

         dim isValid as Bool = true

         ' Also, I think I would simplify this:
         If (String.IsNullOrEmpty(UserLogin) _
             OrElse String.IsNullOrEmpty(UserPass) Then
               isValid = false                   
         End If            

         ' Let the caller know if validation succeeded:
         return isValid 
    End Sub
End Class

Now reference it using class-name where you want to use this, and call the database logic separately from the validation:

Protected Sub LoginButton(ByVal sender As Object, 
                          ByVal e As System.EventArgs) Handles Button1.Click

    if ( SecurityChecker.Validate(username, password) ) Then
         ' Call metod for storing to DB here
    Else
        MsgBox("You need to enter a Username and Password")
    End If

End Sub
Sign up to request clarification or add additional context in comments.

6 Comments

"Static" is called Shared in VB.
Wow. Oops. Thanks, fixing the code now. That's what happens when you switch forth and back between languages several times a day.. =)
@Kjartan. Thanks, in the validate sub it is calling userLogin. userLogin is in the login.aspx.vb module and the sub is in security.vb when I reference it, it can't find the object.
I'm not sure I've understood you correctly. Are you trying to access username and password from your first module with the lines TheNRLPredator.login.(UserLogin) and TheNRLPredator.login.(UserLogin)`? I don't think you can (or should) do that. Like I said, I would recommend separating the validation of username and password, and the actual logging in. You can do this by checking the return value from the validation, then logging in or showing an error message accordingly (I will update my answer to make this more clear). Hope this makes sense?
@Kartjan if I refer to the Button1.click that is in the login.aspx.vb file from the security.vb module it cannot find the withEvents
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.