0

如何在单独的 VB 模块中引用文本框中的值。

在我的 login.aspx.vb 模块中,我有

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

现在在我单独的 Security.vb 模块中,我想检查这些值是否不为空并将它们发送到数据库,但我似乎无法正确引用这些值来执行此操作。任何人都可以帮忙吗?

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
4

1 回答 1

1

securityCheck潜艇在一个班级吗?我会稍微更改一下代码,如下所示:

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

现在使用您要使用的类名引用它,并与验证分开调用数据库逻辑:

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
于 2012-09-11T06:00:41.690 回答