从页面到页面传递数据会加载以前的数据,直到页面刷新

时间:2015-04-27 08:43:36

标签: asp.net vb.net

我有一个按钮,当点击时会使用会话状态将数据传递到另一个页面,但它会从第一个加载实例上的先前事务中加载数据。在刷新之后加载当前数据。我已经搜索过类似问题的解决方案,但我没有找到解决这个问题的方法。

按钮代码

Protected Sub LinkButton9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton9.Click
    'LinkButton9.Attributes.Add("onclick", "window.open('waterprinter.aspx','','height=530,width=530');return false")
    'LinkButton9.Attributes.Add("onclick", "window.open('waterprinter.aspx', '','height=530,width=530','scrollbars=yes','tools=1');return false")


    Dim queryString As String = ""
    Dim SBRANCH As SqlDataReader
    Dim Pdate As Date
    Dim TRN As String = ""
    Dim PaymentFor As String = ""
    Dim CustomerName As String = ""
    Dim CustomerRef As String = ""
    Dim AmtDue As Double = 0
    Dim AmtPaid As Double = 0
    Dim ServedBy As String = ""
    Dim Branch As String = ""

    Try

        If Session("PayID") <> Nothing Then

            Dim MyReader As SqlDataReader
            Dim MyReaderI As SqlDataReader
            Dim MyReaderII As SqlDataReader
            MyReader = dat.DBAction("SELECT * FROM NSSFPaymentsArchive WHERE Authorized = 1 and Status = 'Posted' and PaymentID = " & Session("PayID") & "", DataManagement.DBActionType.DataReader)
            If MyReader.HasRows Then
                MyReader.Read()
                Session("TRN") = IIf(IsDBNull(MyReader("ReferenceNumber")), "", MyReader("ReferenceNumber")) '"50000.00"
                Session("PaymentFor") = IIf(IsDBNull(MyReader("PaymentName")), "", MyReader("PaymentName"))
                Session("Pdate") = FormatDateTime(Date.Today, DateFormat.ShortDate)
                Session("CustomerName") = IIf(IsDBNull(MyReader("CustomerName")), "", MyReader("CustomerName"))
                Session("CustomerRef") = IIf(IsDBNull(MyReader("CustomerRefNumber")), "", MyReader("CustomerRefNumber")) ' "Ura cash A/c"
                AmtDue = IIf(IsDBNull(MyReader("AmountDue")), "", MyReader("AmountDue")) ' "
                AmtPaid = IIf(IsDBNull(MyReader("AmountPaid")), "", MyReader("AmountPaid"))
                Session("AmtDue") = Format(Val(AmtDue - AmtPaid), "#,#.00")
                Session("AmtPaid") = Format(AmtPaid, "#,#.00")
                Session("PaymentOption") = IIf(IsDBNull(MyReader("PaymentOption")), "", MyReader("PaymentOption"))
                Session("Narration") = dat.SpellNumber(Val(AmtPaid), "Shilling")
                Session("Teller") = IIf(IsDBNull(MyReader("CapturedBy")), "", MyReader("CapturedBy"))
            Else
                MyReader.Close()
                MyReader = dat.DBAction("SELECT * FROM NSSFPayments WHERE  paymentid = " & Session("PayID") & "", DataManagement.DBActionType.DataReader)
                If MyReader.HasRows Then
                    MyReader.Read()
                    Session("TRN") = IIf(IsDBNull(MyReader("ReferenceNumber")), "", MyReader("ReferenceNumber")) '"50000.00"
                    Session("PaymentFor") = IIf(IsDBNull(MyReader("PaymentName")), "", MyReader("PaymentName"))
                    Session("Pdate") = FormatDateTime(Date.Today, DateFormat.ShortDate)
                    Session("CustomerName") = IIf(IsDBNull(MyReader("CustomerName")), "", MyReader("CustomerName"))
                    Session("CustomerRef") = IIf(IsDBNull(MyReader("CustomerRefNumber")), "", MyReader("CustomerRefNumber")) ' "Ura cash A/c"
                    AmtDue = IIf(IsDBNull(MyReader("AmountDue")), "", MyReader("AmountDue")) ' "
                    AmtPaid = IIf(IsDBNull(MyReader("AmountPaid")), "", MyReader("AmountPaid"))
                    Session("AmtDue") = Format(Val(AmtDue - AmtPaid), "#,#.00")
                    Session("AmtPaid") = Format(AmtPaid, "#,#.00")
                    Session("PaymentOption") = IIf(IsDBNull(MyReader("PaymentOption")), "", MyReader("PaymentOption"))
                    Session("Narration") = dat.SpellNumber(Val(AmtPaid), "Shilling")
                    Session("Teller") = IIf(IsDBNull(MyReader("CapturedBy")), "", MyReader("CapturedBy"))
                End If
            End If
            MyReader.Close()

            MyReaderI = dat.DBAction("select branchname from branches where solid='" & Session("branch") & "'", DataManagement.DBActionType.DataReader)
            If MyReaderI.HasRows Then
                MyReaderI.Read()
                Session("PayBranch") = MyReaderI("branchname")
            End If
            MyReaderI.Close()

            MyReaderII = dat.DBAction("select FULLNAME from USERS where USERNAME='" & Session("Teller") & "'", DataManagement.DBActionType.DataReader)
            If MyReaderII.HasRows Then
                MyReaderII.Read()
                Session("ServedBy") = MyReaderII("FULLNAME")
            End If
            MyReaderII.Close()


        End If

    Catch ex As Exception

    End Try
End Sub

数据移动到的页面代码(第二页)

Private Sub Page_Load(ByVal sender As Object,ByVal e As System.EventArgs)处理Me.Load

    lblTRN.Text = Session("TRN")
    lblPaymentFor.Text = Session("PaymentFor")
    lblPaymentDate.Text = Session("Pdate")
    lblCustomerName.Text = Session("CustomerName")
    lblCustomerRefNo.Text = Session("CustomerRef")
    lblAmountDue.Text = Session("AmtDue")
    lblAmountPaid.Text = Session("AmtPaid")
    lblServedBy.Text = Session("ServedBy")
    lblBank.Text = "IMPERIAL BANK"
    lblBranch.Text = Session("Branch")
    Label2.Text = Session("Narration")


End Sub

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

我注意到在按钮点击执行逻辑之前执行了页面加载逻辑。所以我把按钮上的逻辑点击到另一个我在第二页的页面加载时调用的函数。我确保在第二页的页面加载之前调用了该函数,并且它有效。谢谢你的贡献。