簡體   English   中英

如何在兩個過程之間傳遞變量數據

[英]How to pass variable data between two procedures

我試圖將變量信息從一個過程傳遞到另一個過程,.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可以訪問該信息。

目前尚不清楚如何在代碼中調用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM