我正在尝试将变量信息从一个程序传递到另一个程序,我在.net上没有很多经验,我无法找到有关这样做的更多信息。
Sub ValidationScript()
Dim checkVar As Boolean
'First consistency check \\ Length based check
If emailP.InnerText.Length > 3 Then
If passwordP.InnerText.Length > 5 Then
checkVar = True
Else
Con1.InnerText = "You have entered an Incorrect Email or password."
checkVar = False
End If
Else
Con1.InnerText = "You have entered an Incorrect Email or password."
checkVar = False
End If
End Sub
Sub loginBtn1_Click(checkVar As Boolean) Handles loginBtn1.ServerClick
if checkVar = true then
Response.Redirect("Home.aspx")
end sub
我试图从checkVar获取第二个子loginBtn1可以访问的信息。
答案 0 :(得分:1)
目前尚不清楚如何在代码中调用ValidationScript,但现在我认为您只需将Sub ValidationScript
更改为返回布尔值的Function ValidationScript
Function ValidationScript() As Boolean
Dim checkVar As Boolean = False
'First consistency check \\ Length based check
If emailP.InnerText.Length > 3 Then
If passwordP.InnerText.Length > 5 Then
checkVar = True
Else
Con1.InnerText = "You have entered an Incorrect Email or password."
End If
Else
Con1.InnerText = "You have entered an Incorrect Email or password."
End If
return checkVar
End Function
然后在Click事件中调用它(但使用正确的参数)
Sub loginBtn1_Click(ByVal Sender as Object, ByVal e As EventArgs ) Handles loginBtn1.ServerClick
if ValidationScript() = true then
Response.Redirect("Home.aspx")
else
.....
End If
end sub