如何在单独的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
答案 0 :(得分: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