1

奇妙な問題があります。私は多くのセッション変数を使用しているので、ページがポストバックを行うたびにすべてを前後に渡す必要はありません。私はこれを何年もやっているので、完全に途方に暮れています。

App_CodeフォルダーにSessionHandler.vbというファイルがあり、次のコードが含まれています。

Imports Microsoft.VisualBasic

Public Class SessionHandler

    Private Shared _chgLinePkNum As String = "0"
    Private Shared _chgStudentIDPk As String = "0"

    Public Shared Property chgLinePkNum() As String
        Get
            ' Check for null first
            If (HttpContext.Current.Session(SessionHandler._chgLinePkNum) Is Nothing) Then
                ' Return an empty string if session variable is null.
                Return "Nothing"
            Else
                Return HttpContext.Current.Session(SessionHandler._chgLinePkNum).ToString()
            End If
        End Get

        Set(ByVal value As String)
            If (value Is Nothing) Or (value = "") Then
                HttpContext.Current.Session(SessionHandler._chgLinePkNum) = "Nothing"
            Else
                HttpContext.Current.Session(SessionHandler._chgLinePkNum) = value
            End If
        End Set
    End Property

    Public Shared Property chgStudentIDPk() As String
        Get
            ' Check for null first
            If (HttpContext.Current.Session(SessionHandler._chgStudentIDPk) Is Nothing) Then
                ' Return an empty string if session variable is null.
                Return "Nothing"
            Else
                Return HttpContext.Current.Session(SessionHandler._chgStudentIDPk).ToString()
            End If
        End Get

        Set(ByVal value As String)
            If (value Is Nothing) Or (value = "") Then
                HttpContext.Current.Session(SessionHandler._chgStudentIDPk) = "Nothing"
            Else
                HttpContext.Current.Session(SessionHandler._chgStudentIDPk) = value
            End If
        End Set
    End Property

非常に単純です...次に、私のコードでは、SessionHandler.chgLinePkNumによってプロパティを参照します。このコードブロックには、LineItemNumber=1およびStudentID=[実際のID番号]があります。

    If IsParking And checkbox.Checked = True Then
        SessionHandler.chgLinePkNum = LineItemNumber
        SessionHandler.chgStudentIDPk = StudentID
        peParkingRegistration.Show()
    End If

最初の行が実行されると、chgLinePkNumは期待どおりに1に設定されます。奇妙な理由で、chgStudentIDPkも1に設定しています。次の行が実行されると、chgStudentIDPkが正しいStudentID番号に設定されます。問題は、chgLinePkNumもStudentID番号に設定されることです。

デバッガーで1行ずつ実行しましたが、各プロパティセット関数は呼び出されたときにのみ実行されます。「HttpContext.Current.Session(SessionHandler._chgLinePkNum)=value」がchgStudentIDPkの値をどのように設定しているかを理解できません。その逆も同様です。

4

1 に答える 1

1

まったく同じ値を持つこれらと何か関係がありますか?

Private Shared _chgLinePkNum As String = "0"
Private Shared _chgStudentIDPk As String = "0"
于 2012-06-21T21:13:05.607 に答える